Using Settings in C# Windows Forms applications

It suprised me how poor the documentation is for using Settings with a Windows Form application written in C#. I noticed recently the following article posted on the MSDN site, http://msdn2.microsoft.com/en-us/library/aa730869(VS.80).aspx. However, there is an easier way. Create the settings you want to persist in the projects settings page as normal. Then, rather than hand coding the mapping between the setting file and your UI controls go to the form designer. In the properties of the UI control select Application Settings->Property Bindings. Map the appropriate property (e.g. Text) to the required setting value. All done, well not quite. If you want to persist the changes you need to add the following to the forms closed event…

Properties.Settings.Default.Save();

There all done, persisted settings with only one line of code….nice.

More DOM differences

My incursion into the land of DOM scripting hit upon another difference between IE and Firefox, another simple example…

<Div id="test">
Hello there
</Div>

The task, use JavaScript to change the text in the Div, easy eh?

document.getElementById("test").firstChild.value = "new text"
or
document.getElementById("test").innerText = "new text"

Well, turns out I used both! IE seems to like the 2nd and Firefox the 1st, with neither complaining about the other. Now I can see why the AJAX libraries have their DOM abstraction functions!

Generic dictionary indexer behaves differently

Today I discovered, the hard way, that if you ask for a key value that doesn’t exist in a generic dictionary you get an exception, whereas for specialised dictionaries (or your own derived ones) you get null. This was especially annoying has I have a load of code expecting null and a colleague changed the dictionary to a generic one. So I had to change the indexer to do a quick "contains key" to return null if the key doesn’t exist.

Checking out all (and only) the projects for a Solution

Visual Studio (VS2005) doesn’t comes with a fair bit of Source Safe integration but it also has some annoying traits.
The default behaviour of checking out a single project is to also check out all the files within it.  Ok it only takes a few mouse clicks to stop this but it’s annoying. However, this is really frustrating when you’re working on a solution with 10s or 100s of projects. So I wrote a quick macro to avoid these issues, and it goes something like this…

Dim currentProject as EnvDTE.Project
for each currentProject in DTE.Solutions.Projects
    DTE.SourceControl.CheckOutItem(currentProject.FullName)
next

Who changed that file?

Writing a file watcher program at the moment but I’ve hit a problem, I can’t seem to discover who changed the file last. I’m sure Windows keeps the information but I can’t find it. Ok, so the users can turn on file auditing so I guess it’s no big deal but I can’t help thinking I’m just missing something. The other bit of information I was trying to locate is the ‘File Version’ of a DLL. After following seemingly countless dead ends looking at FileInfo, FileAttributes, etc I discovered that that this information is…under System.Diagnostics!  Obvious really!?

Browser DOM trouble

Dabbling with a bit of web design this evening and was happily writting my XHTML 1.1 compliant page with a bit of standard JavaScript. I was developing this using IE7 and completed my little test. The test consisted of a DIV with three nested DIVs each containing their own specific elements. The JavaScript was supplied with the outer/parent DIV as an argument and would tell me how many childNodes it had, simple. Ran it in with IE and got 3, correct. Ran it in FireFox got 7, WHAT! Firefox counts *all* the descendants as children, surely this can’t be right? Oh well so much for "standards", no wonder web site design is such a pain in the padding-bottom!
Example snippet…

<div onclick="alert(this.childNodes.length);">


  hello

  <div></div>


  <div>


    <div></div>


    <div></div>


    <div></div>

  </div>


  <div></div>


</div>

Virtual Keyboard and Remote Desktop

When I connect to my UK PC from the US (grrrr) Mac I can usually remember where the different keys live. However, there a couple of keys that regardless of my PC keyboard locale just don’t seem to work from the Mac, namely "|" and "\" (although it works fine from Parallels!?). To get around this I’ve now started using the Accessability feature of the On Screen keyboard. Just remember to set it to the correct number of keys otherwise you still won’t see those characters!
 

IE7 Vista or XP?

I took the dreaded Windows Update of IE7 on my XP machine. I don’t like it. It seems to be really slow at rendering pages and has a horrible problem where it simply seems to fail to respond when you change the URL in the address. It’s so bad that I have to close and reopen the browser to change the address. RUBBISH!! Firefox it is then.
 
So it was with some interest that I started using IE7 on Vista. Works a treat, rendering speed is fine, changing URL works as you’d expect. So what’s going on here, surely not a way to force me to upgrade my XP machine is it 😉
 

Will Apple be undone by their own strategy?

I must confess two things, 1. I enjoy my Mac book 2. I can’t stand people that glorify the Mac. I’ve owned Mac’s for about nine years and subscribed to MacUser for the same amount. I’ve seen the Mac go from an "also ran" to a potential leader of the pack. All through this period people have written in MacUser saying how great the Mac is compared to the Windows PC or rather just the PC. This months edition contained a letter that really made my blood boil. Basically the letter was saying that this guy was telling a family member to ditch their PC because of all the trouble they had with a virus. The premise to switch was that you won’t get a virus on a Mac. How stupid. Sure statistically I bet there are a thousand Windows based viruses for ever Mac one, but this is all about popularity rather than a secure system. I’ve long argued that rather than heap praise on one side or the other both Apple and Microsoft produce annoying operating systems and applications. Their hardware isn’t always that much better either. My MS Force Feedback joystick failed to work on XP, two Apple Macs were delivered dead-on-arrival, Ipod Nano scratches by simply looking at it, OSX is black or white OS, either your totally pandered by UIs or your down in the guts of Unix, Vista attempts to secure itself by panicking the user into never installing anything! What I’m saying is stop the my OS is better than your and start asking your preferred vendor to produce better quality products.

The real choice between PCs and Macs is flexibility vs. out-of-the-box compatibility. Mac’s only contain a very restricted set of hardware, basically you could say that the only options are how much memory or disk space you have (yeah ok there are more choices but it’s not far from the truth). This means the a Mac OS only has to worry about a very small set of hardware and hence the chance of a dodgy hardware drive getting into the mix is greatly reduced. Whereas PCs come in all sorts of permutations, some with downright cheap and nasty kit. Windows bravely attempts to cope with all of this, but with all these permutations of kit getting a conflict is greatly increased. So for me, when I want to build my optimum machine I go the PC route, when I want something that will be pretty dependable without me doing loads of researching then a Mac would be a good choice.

Ok rant over, now onto the title of this blog entry. Apple have made a
very big push at the home user to switch by concentrating on what the
average Joe user wants. Pictures, music, internet browsing and email.
Ok so you get that with Windows too but why should that matter?
(Although Apple charge for their email services). We swallow the slick marketing and go an buy our pretty iMac and put it into our homes, in fact it’s so versatile we put it into our living rooms/lounges. Great, we’re thrilled. But hang on what’s this on the horizon? A device that sits in our living rooms/lounges you say. Plays music, browse the internet, email, etc? Apple have been so keen to market the Mac as a simple users tool that stuck the Mac in the middle of the road where the consoles trucks travel up and down. Next gen consoles will do everything that the Mac campaign says you want from a computer. Plus they play cool games…hmm the choice of what to switch to looks obvious now, I don’t want a PC/Mac I want Nintendo, Playstation, 360…

Apple developers from WWII Germany?

I was just staring around my room and focused on the ‘Company of Heroes’ game. Next to that is my ‘Mac OS Tiger killer tips book’. It then struck me that the code names of OS X match the names of German Tanks from WWII. I wonder where this will lead? Focker Wolf 190 coming next?
 
[Edit]
Actually it’s Leopard, so I’m fully expecting iPanzer any time now.