Tuesday, June 22, 2004

SystemIcon to Image

Today I wanted to display a system icon on a form. I found the SystemIcon class that contained what I wanted to show. I plunked down a PictureBox on the form. Lastly, I hooked up the image in the form constructor using something like:

m_pictureBox.Image = SystemIcon.Exclamation.ToBitmap()

Nothing could have been more simple... right? Wrong.

The icon displayed on the form looked pretty... well... sad. As I mentioned yesterday, I am professing to crafting software. This might do for some but not for me. The image was not smooth like the stock icons are. I will not profess to knowing a lot about graphics but I do know when a graphic doesn't look good.

So I went down the shortest path, but obviously that was not the correct one. So I took a step back and studied my alternatives. Was it something I could do with SystemIcon, Icon, or PictureBox? All of them turned up nothing.

After think about what was going on under-the-hood, I realized that Mr Bitmap had joined in the party. Studying the Bitmap class, I found a possible solution...

m_pictureBox.Image = Bitmap.FromHicon(SystemIcons.Exclamation.Handle);

Having nothing to lose (other than time), I hooked it up and guess what that does what I really wanted - a good looking system icon on my form.

0 Comments:

Post a Comment

<< Home