Want to make your WinForms application look just a bit more professional? Check out this easy implementation of the StatusStrip!
Sunday, April 12, 2009 12:59 PM
Want to make your WinForms application look just a bit more professional? Read on for one quick'n'easy thing you can do to bran your newly created (or in maintenance) WinForm with your company logo!
Do you want to make your Windows application look juuuuuuuust that little bit more polished? Just a bit more professional? To separate yourself from the rest of the pack, but not cost you an arm'n'leg? I have JUST the trick! In less than the time it takes to walk over to the coffee machine and get a cup of liquid gold, you can add a small class touch to your WinForm! This applies to WPF apps too, but the source code, pics and etc are all WinForms based (for now, I'll put a WPF app up later).
Here is what the completed version of the CompanyLogoOnStatusBar looks like. Notice the company logo on the bottom right hand side corner. A couple of things to notice/mention are:
- The image is in a ToolStripStatusLavel control, yup, the Label is being used to hold the image, fancy trick eh?
- You still have resizing control over the form, notice the resizing handle in the extreme bottom right hand side? Yup, that still works perfectly!
- Along with resizing, the company image will always stay in the bottom right hand side, just what you want, AND you don't have to do anything to make that work, the StatusStrip does all the heavy lifting for you. BEAUTY!
- And lastly, the magic to make this work, isn't actually the image/company logo, no, it's the ToolStripStatusLabel juuuuust previous to the CompanyLogo, you'll see this in a sec.
Let's back up, just a bit. When you are looking at your form for the first time (or one hundredth time if you're in maintenance) , you're going to want to put a StatusStrip control onto your form.
When you place it onto the form, your form will look like this (look at the control at the bottom).
Now that's done, you'll have to three other things, a company logo, setup two labels in the StatusStrip and a couple key properties and we're done.
When you get your company logo, try to get a version which will fit into the status bar, should be 20pixels high. Why? Cause if it's too big, it'll push the StatusStrip to match your logos height and if it's too high, it'll look weird. You can try it out to see what you think.
Setup Two StatusStripLabels
You can of course have more, but at a minimum to get this to work, you'll need to setup at least two. One for the company logo on the right hand side, and one for the status messages, but more importantly to set a property (Spring = True) which will always push the company logo picture to the far right hand side. You can choose to put no text into that status label if you wish, but I figure if I have the option, I'll give the user some feedback.
As I just mentioned, this is where the magic happens. This is the settings for the Company Logo with the imporant ones circled in red. Notice how the image is coming from the resources? The DisplayStyle = Image makes sure not to include the Text property in the display and the ImageScaling make sure not to grow/shrink the image inappropriately.
Next is the properties for the lable just before the company logo. Notice the Spring = true, this is what forces/pushes the company logo to the far right all the time as the form is resized, this is key to make this all work out. Otherwise your company logo will always appear on the left hand side of the form tight up against your message text. Maybe thats what you want, in that case, put back the default value. Another important setting is to the TextAlign = MiddleLeft, this forces the text to the left hand side, otherwise the default is in the middle. That could be ok for you too, it's your call.
Another small use for the company logo is to provide your customer with a quick'n' easy link back to your company's corporate website or maybe to your forums or support environment. The possibilities are endless! :>
At the end of all this, you'll have a spiffier form and a more professional looking application for your company. Now go grab that coffee I was talking about and get coding! :>
Source Code: http://www.pchenry.com:8080/svn/Blog/trunk/2009/CompanyLogoOnStatusBar