I rolled my own dialog in WinForms 2.0 and wanted to use the images that is available when using the MessageBox by way of the MessageBoxIcon enum. To do what I wanted, I used the System.Drawing.SystemIcons class, which exposed static references to several system icons, of course. Here’s an example use of the Warning icon in a PictureBox:
[csharp]
System.Windows.Forms.PictureBox pb = new System.Windows.Forms.PictureBox();
pb.Location = new System.Drawing.Point(14, 7);
pb.Size = new System.Drawing.Size(48, 41);
pb.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
pb.BackgroundImage = System.Drawing.SystemIcons.Warning.ToBitmap();
[/csharp]
System.Drawing.SystemIcons also has Application, Asterisk, Error, Exclamation, Hand, Information, Question, Warning, and WinLogo.
The System.Drawing namespace also has SystemBrushes, SystemColors, SystemFonts, and SystemPens.
I just checked my web site reports on nextSTAT, and noticed that I already have one “real” visitor since I setup SurplusMeat earlier this week.
The visitor did a search on technorati.com using the term “shawn burke”. And referring to the visitor details image, it appears that the visit originated from Microsoft Corp. Putting my detective hat on, I am most certain that the visitor was Mr. Burke himself or someone with very close ties to him. Interesting….
I was asked by our user interaction designer to make Enter key presses mimic a Tab key press by moving focus to the next control where TabStop=true. Sounds simple enough. But after several fruitless searches on Google, I thought I would have to resort to using unmanaged code. Luckly, I finally found a blog post with the answer that I was looking. Well, the post itself didn’t solve my problem, but the comments pointed me in the right direction.
The initial suggestion to override the form’s OnKeyUp event doesn’t apply to my case because my text fields were in a panel. ProcessKeyTab is a protected method that can only be called when you extend a control that is derived from ContainerControl, such as Form or Panel. Since I didn’t extend the Panel I was using, I couldn’t call ProcessKeyTab.
After reading the comments, I found that the answer lies in using the static SendKeys.Send method. In each TextBox that you want to treat Enter as Tab, simply handle the KeyPress event and call SendKeys.Send(”{TAB}”) if the key pressed is an Enter key.
SurplusMeat is now running version 2.0.3 of WordPress. I haven’t noticed any bugs or problems yet. I’m still running version 2.0.2 on my local development box and on MetricsPad.
Also, I switched my theme to Hemingway Reloaded by WordpressLab. I chose it for its simplicity and liquid layout. Aside from the mods I’ve already made, I plan to give it a little bit more color and usability. I’ve already started by giving some of the anchor tags (and their hover states) the traditional blue hyperlink color.
<soapbox>
No offense to the original designer or all the “designers” out there, but why do they insist on making links hard to spot quickly. The blue text with underline just screams click me. Well, it doesn’t have to be blue, but you get the point. And while I’m on my soap box, why do so many sites make their default font size so small. For example, I visit Shaun Inman’s blog on a regular basis, and with each visit, I have to press Control + (plus sign) a couple times in Firefox to get the text size big enough so that I can actually read it. I understand that my monitor is set at a high resolution (1600×1200 at least), but Shaun is a smart guy. He can figure out that I’m at a high rez and offer me a different style sheet that makes his great content more readible by default.
</soapbox>
Executive Summary
Great book on understanding and customizing Windows Forms! Quoting the book’s foreward given by Shawn Burke, Development Manager, Windows Forms Team, Microsoft Corporation:
Matthew MacDonald … has built a great resource for developers using Windows Forms to create great, rich applications. Whether the goal is to write components for internal use or a full application, this book will help you get there and deliver great results.
Mr. Burke goes on to say:
The practical, task-based approach, of Pro .NET 2.0 Windows Forms and Custom Controls in C# allows it to cover a wide range of Windows Forms topics, but still provide the technical depth to help developers deliver features. While many other resources read more like technical reference docs, Pro .NET 2.0 Windows Forms and Custom Controls in C# does an excellent job of filtering the information down to what developers really need to harness the power and innovations of Windows Forms 2.0 to deliver truly world-class client applications.
I couldn’t agree more with Mr. Burke. Since I’ve had the book, there hasn’t been a day gone by that I haven’t found at least one answer to my WinForms problems.
(more…)