Friday, November 30, 2007

Light reading at the traffic light



In case you were wondering, the book in the picture is the bible.

Thursday, November 29, 2007

Five steps for creating a transparent user control

Guest post from Eyal Ron:

After much testing this is the correct formula for a truly transparent user control:

  1. Derive from Panel rather then UserControl.

  2. Override the OnPaintBackground function:
    protected override void OnPaintBackground(PaintEventArgs pevent)
    {
    //do nothing
    }

  3. Override the OnMove function:
    protected override void OnMove(EventArgs e)
    {
    RecreateHandle();
    }

  4. Override the CreateParams property:
    protected override CreateParams CreateParams
    {
    get
    {
    CreateParams cp = base.CreateParams;
    cp.ExStyle = 0x00000020; //WS_EX_TRANSPARENT
    return cp;
    }
    }

  5. Override the OnPaint function:
    protected override void OnPaint(PaintEventArgs e)
    {
    Graphics g = e.Graphics;

    //Do your drawing here
    .
    .
    .

    g.Dispose();
    }

Thursday, November 22, 2007

Special consideration for the ThreadAbort exception

As a rule, I never want to see an unhandled exception crashing my application with the .Net error dialog and without logging the error.
Therefor I always hook both the AppDomain.UnhandledException and the Application.ThreadException events to catch those exceptions, log them, and close the application gracefully.

Turns out I overlooked one small detail - the ThreadAbort exception, raised by a call to the Thread.Abort method. It's not a best practice to use it (you should let the thread shut down itself), but it may be used by a 3rd party code, so it can't be ignored.

However, since it's not an actual exception there is no logic in shutting down the application due to this exception.

Acer's localized international warranty

I have been looking to buy a notebook computer for some time now.
Someone told me about a friend of his who bought a new Acer notebook during a trip to the U.S. as a temporary replacement for his malfunctioning computer, and now he wants to sell this new notebook computer (as his old computer was fixed).
It seems he got it in the U.S. with an international warranty.

So I called Acer's locale dealer (Newpan) to check this out.
Turns out the Acer management dictated that an Israeli who buy a notebook in the U.S. will not have warranty in Israel.
In other words: If you buy a computer in the U.S., you get international warranty as long as you use it inside the U.S.

Sunday, November 18, 2007

Validation of a NumericUpDown control

The NumericUpDown control has a built-in validation:

  • Values smaller than the minimum are replaced by the minimum
  • Values larger than the maximum are replaced by the maximum

This may lead to a situation in which the user entered an invalid value and pressed the form's "OK" button, leading to saving of a value completely different than the one entered with no notification.
To prevent this, enter your own validation code into the validating event (using the "Text" property instead of "Value"), and if the validation fails set the e.Cancel argument to "true".

From the people who brought you "Catastrophic Error"

Now comes another great error dialog:
"The Operation completed successfully" error dialog.

Saturday, November 17, 2007

Create the ultimate business card

During the David Platt's lecture I received a business card from him.
The card's title is "Rolling Thunder computing" (his company), and his title is: "Supreme and Exalted, Dictator-for-life"
I think that's the best job title I have ever seen on a business card, and even better - it makes people pause and remember him because it's unusual.
Do you have special titles on your business cards?

Wednesday, November 14, 2007

David Platt on Why Software Sucks

I went to a lecture by David Platt on the subject of "Why software sucks", which discusses what is wrong with software today (hint: it's mostly designed by programmers) and how we can improve it.
From listening to a previous ARcast with him I already knew he is a very entertaining speaker, and he proved me right (in fact, I kept thinking I could bring my wife to one of his lectures and she would have enjoyed it as well).

David began his presentation with a screenshot from the Better Business Bureau in the US, listing complaints by industry, and the amazing thing about it - people dislike software more than they dislike used-cars salesmen!

The main idea of the presentation (backup up with all sorts of amusing anecdotes):

  • People don't buy software for the sake of the software itself - they buy software to get something done. They are not interested in using the software, they want to have used it.
  • Programmers tend to design software for people like them, while most users are very different.

Platt's solution resolved around 5 key points:

  1. Add a virgin to the team - add someone to the team with zero knowledge about the inner workings of your software.
  2. Break convention if needed - don't behave in a certain way just because all every application behaves the same way.
  3. Do not let edge cases complicate the main stream - extra features aimed at edge cases complicate your software and make it counter productive.
  4. Instrument (Carefully) - Try to gather information about the way users use your software without harassing them.
  5. Question each decision - ask if each decision is taking your project closer to the result or further away from it.

The lecture itself was followed with a Q&A session, in which I asked him a question (which landed me a signed copy of his book - thank again, David!):
If programmers are so bad at designing UI, why not bring in a specialist to do it?
His response (after correcting me for saying "Graphics designer" instead of "User interface designer") was it's actually a good idea, since most of the industry is already headed for specialization in various subjects.

I found another podcast on ITConversions network, and here are two short videos from the presentation:



Sunday, November 11, 2007

Three wrong assumptions

Did some blog reading today, and found out several assumptions I had which were wrong:

  • Assumption: "Protected Internal" means both protected and internal
    Wrong: It means Protected OR Internal.

  • Assumption: 32bit Windows is limited to 2/4gb ram
    Wrong: It's limited to 2gb of ram per application.

  • Assumption: OpenFileDialog is harmless
    Wrong: It loads a mini-explorer, including all the extensions you have installed.

Buy a shirt with this blog's tagline


Just did some searching and found this site, which sells T-shirts with the tagline: "Programming is an art form that fights back" (which I "stole" from Chad Z. Hower, aka Kudzu)

Thursday, November 8, 2007

Microsoft Windows Live press conference

I was lucky to be invited to the official press conference of announcement of the new Live service from Microsoft.
It looks very promising, and would give Google (and Picasa) a tough competition.

Here are some interesting points from the presentation:

  • Microsoft global market status: According to the speaker there are 280 million MS Messenger users worldwide, and the number of Hotmail users is three times the number of GMail users. If these numbers are correct, Microsoft can still hurt Google badly.
  • The new mail service (Windows live mail) allows integration with Messenger - you can see your friends online while typing a message to them and start a chat. (Additional interesting features - contacts lists, RSS support). I was also told the spam prevention mechanism (a major problem for Hotmail users) was improved - I intend to check that.
  • MS Messenger itself had an improved integration with mobile devices - you can leave voice messages to friends online.
  • In the photos department Microsoft is in direct competition with Picasa, which had the advantage so for for being a "one stop shop" for all photo related applications. The new Live client application allows you to send photos to friends, with the mail containing only small thumbnails and a photo sharing site is generated automatically that allows viewing/downloading of the original photos. Additional features include embedding photos in a blog post, and creating an event-dedicated shared site, in which participants can upload photos and share them with each other.
  • All of these applications come wrapped up in a single installer which allows you to select the desired installed features. It's a serious upgrade for Outlook Express users and Messenger users, and I recommend installing Windows live photo gallery application.
  • All of these services are aimed at the personal user - for organizations Microsoft has Office Communicator and a beta version of calendar sharing site.
  • In the future there will be an integration between MS Live and Media center, allowing you to read and manage blogs, photos and contacts using the TV screen.
  • You can register to the new service and receive a brand new mail address (you name may still be available!). Us users are directed to the Live.com domain, while users in other countries (depending on the first language in the browser's languages configuration) may choose other domains.

Here are some pictures I took which are hosted in the new Live space I created:

Saturday, November 3, 2007

Heroes in Microsoft?

I was just erasing promotion mail from my mailbox when I noticed the photo:

I'm not 100% sure, but this looks a lot like James Kyson Lee ("Ando") from "Heroes".