I made a stupid C# mistake today. In the constructor of my form, I had an OpenFileDialog.Show() call (to get the name of a file to operate on.) When I ran the program, the OpenFileDialog would show as expected. But after I pressed okay, the main application would not be the focused window.
It took me too long to figure out that since I was calling OpenFileDialog in the constructor, the Application wasn't initialized yet and so the OpenFileDialog.ShowDialog() was using another window as its parent. Using the call OpenFileDialog.ShowDialog(this), where this is the current form, made everything work as expected.
Another problem I had was not being able to exit the program by calling Application.Exit() in the constructor. Apparently, the Application isn't initialized before the constructor returns. So I'd either have to throw an exception for whoever is calling Application.Run() or else use the Environment.Exit(). I went with Environment.Exit()... not sure if there's any reason not to.
I spent a long time trying to figure out why I couldn't set an item as selected for a ListView by setting the Select property to true. Apparently, you're supposed to call ListView's Select method. I should look into this more.
More:
Use the Shown Callback in forms if you want to do stuff to controls outside of the contstructor but before things really start running. In the constructor, there are no event handlers and you can't exit the application without using Environment.Exit.
If you want to use a checkbox in a list view, that is built in. If you're listening for items checked, make sure you don't add the ListViewItem to the list until the checked value is correctly set.
When I first started .Net development, I couldn't get the KeyDownEvent listener to work for my form. It turns out I forgot to change the form's KeyPreviewProperty to true.
Monday, May 16, 2011
Monday, May 09, 2011
iPhone Pains
Man, at this point I wish I had gone with an Android phone instead of an iPhone. But I have too much time and money burned (NOT INVESTED) on the iPhone to make it worthwhile. My laptop died last month (I think Taiwan's summer destroyed its ability to stay cool.) I used that laptop to sync with my iPhone and because of the way the iPhone is designed, I needed to resync with iTunes on a new computer, which would delete all my music and playlists. Luckily, the hard drive from my busted laptop was still good so I could get my music. Otherwise, I would need to spend A LOT of time looking for safe, trustworthy programs to get my music off my iPhone. I've heard they exist, I just don't want to spend the time figuring out what they are and how to use them safely.
So I needed to copy all the music from the laptop onto a new computer. I ended up using an old Mac Mini I had lying around, (might as well find a use for that expensive lesson on how I do not enjoy developing iPhone software in my freetime.) I needed to figure out how to copy all my playlists (hint: figure out where your iTune's library.xml file is and import it. Use some text editing software and do a "replace all" on your music directories from your old computer to where they live on the new computer.)
I spent an entire evening doing all of this, which was really annoying. I really, really wish I didn't have to jump through all these hoops to add new music or to sync other items with my iPhone. While the iPhone is pretty, using it requires so much awkward hoop jumping that one day, I know I'm just going to give up on it.
So I needed to copy all the music from the laptop onto a new computer. I ended up using an old Mac Mini I had lying around, (might as well find a use for that expensive lesson on how I do not enjoy developing iPhone software in my freetime.) I needed to figure out how to copy all my playlists (hint: figure out where your iTune's library.xml file is and import it. Use some text editing software and do a "replace all" on your music directories from your old computer to where they live on the new computer.)
I spent an entire evening doing all of this, which was really annoying. I really, really wish I didn't have to jump through all these hoops to add new music or to sync other items with my iPhone. While the iPhone is pretty, using it requires so much awkward hoop jumping that one day, I know I'm just going to give up on it.
Advice to a man for a successful marriage
Okay, today I'm going to share one of the secrets to a successful marriage (for the husband.) This secret was passed down to me by a wise former boss of mine. Here's what he told me:
"At some point, especially in the beginning of marriage before she learns better, she will inevitably ask you to make a choice. This should be your most frequent response:
1. Slowly look over each choice. You don't have to really care, but it needs to appear like your thinking about them.
2. Pause until the count of 3.
3. Ask her what she thinks. She will have an opinion. You must make her voice it.
4. Reply: Y'know, that's what I was leaning for too. Let's go with that one."
This works very well, just don't be too obvious. And remember, in an argument, it's not a question about who is right or who is wrong. It's just about who cares more. I read that from Scott Adam's blog, and although I don't always agree with him, I agree with him in that.
(Yes, in case you're worried, there's loads of sarcasm in this entire post, Maybe. Ha ha.)
"At some point, especially in the beginning of marriage before she learns better, she will inevitably ask you to make a choice. This should be your most frequent response:
1. Slowly look over each choice. You don't have to really care, but it needs to appear like your thinking about them.
2. Pause until the count of 3.
3. Ask her what she thinks. She will have an opinion. You must make her voice it.
4. Reply: Y'know, that's what I was leaning for too. Let's go with that one."
This works very well, just don't be too obvious. And remember, in an argument, it's not a question about who is right or who is wrong. It's just about who cares more. I read that from Scott Adam's blog, and although I don't always agree with him, I agree with him in that.
(Yes, in case you're worried, there's loads of sarcasm in this entire post, Maybe. Ha ha.)
Wednesday, May 04, 2011
Subversion
Notes I wrote up in 2006 regarding subversion. It functions as an intro guide to subversion, both as a client and as an administrator.
I've been using subversion (nope, not a git guy yet) for most of my own work, I even got our projects at my current job onto subversion. It's much better than source safe/offsite (which I used at a previous job) and I even prefer it to CVS. Subversion is designed specifically to be a modern replacement for CVS and shares a number of the same key developers. It uses a copy-modify-merge for file sharing. To read more about subversion, you can read their very good documentation at http://svnbook.red-bean.com/. The following is a link to an appendix from the svnbook that introduces subversion for cvs users. I think that it will be a very helpful and painless way to quickly understand subversion with a cvs background. You can read it starting at http://svnbook.red-bean.com/en/1.2/svn.forcvs.html.
I've been using subversion (nope, not a git guy yet) for most of my own work, I even got our projects at my current job onto subversion. It's much better than source safe/offsite (which I used at a previous job) and I even prefer it to CVS. Subversion is designed specifically to be a modern replacement for CVS and shares a number of the same key developers. It uses a copy-modify-merge for file sharing. To read more about subversion, you can read their very good documentation at http://svnbook.red-bean.com/. The following is a link to an appendix from the svnbook that introduces subversion for cvs users. I think that it will be a very helpful and painless way to quickly understand subversion with a cvs background. You can read it starting at http://svnbook.red-bean.com/en/1.2/svn.forcvs.html.
Monday, May 02, 2011
Executing Java from VBScript
This post is simple, it's just some Visual Basic Script for executing a jar and keeping the text output in a variable:
- Set objShell = WScript.CreateObject("WScript.Shell")
- Set objExecObject = objShell.Exec("java -classpath JavaCode.jar JavaClassName")
- Do Until objExecObject.StdOut.AtEndOfStream
- Results = Results + " " + objExecObject.StdOut.ReadLine()
- Loop
Subscribe to:
Posts (Atom)