The latest release of Component One's Studio for WinForms completes the implementation of the Office 2010 visual styles across the entire range of controls. If you're like me and you're always keen to seeing what's new (and of course with visual styles it's quite literally a case of 'seeing' what's new) then you'll almost certainly have given them a spin by now. Of course what you, the developer, think looks really cool may well not suit the tastes of your end user and when it's all said and done it's them that you need to satisfy.
If you've ever changed the style in Microsoft's Office 2007 and 2010 suites then you'll already know that whatever change you make in one of the programs will be reflected across all of the programs in the suite (if you didn't know then you should give it a try and see for yourself). By default the Office suites load their respective 'blue' themes. If you use the C1Ribbon template as a base for a new project then you'll be aware that a style button has been added to the template allowing your end user to easily select a style of their choice. However the choice that they make will only last as long as your program is running, unless you make provision of course to remember their choice and reinstate it next time your program starts.
Visual studio makes this quite easy to do via the Settings tab in the project properties. Begin by opening up your project's properties and selecting the Settings tab. Create a new setting (in this example I called it VisualStyleToUse and set its type to be of C1.Win.C1Ribbon.VisualStyle. Finally, set its scope to be User and its value to be whatever you wish it to be.) The 'User' scope is very important, setting it to Application would mean that your user couldn't change it.
With that done if you're using the C1Ribbon template go to the main form, select the C1Rribbon control, and from its properties open up the Application Settings. Select Property Binding and click on the ellipsis.
In the ensuing dialog that opens select VisualStyle and bind it to the user setting that you've just created.
Now add a single line of code to the bottom of the relevant code section where the visual style is changed:
Private Sub visualStyle_PressedButtonChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles blue2007Button.PressedButtonChanged If blue2007Button.Pressed Then c1Ribbon1.VisualStyle = VisualStyle.Office2007Blue ElseIf silver2007Button.Pressed Then c1Ribbon1.VisualStyle = VisualStyle.Office2007Silver ElseIf black2007Button.Pressed Then c1Ribbon1.VisualStyle = VisualStyle.Office2007Black ElseIf blue2010Button.Pressed Then c1Ribbon1.VisualStyle = VisualStyle.Office2010Blue ElseIf silver2010Button.Pressed Then c1Ribbon1.VisualStyle = VisualStyle.Office2010Silver ElseIf black2010Button.Pressed Then c1Ribbon1.VisualStyle = VisualStyle.Office2010Black ElseIf windows7Button.Pressed Then c1Ribbon1.VisualStyle = VisualStyle.Windows7 End If My.Settings.VisualStyleToUse = c1Ribbon1.VisualStyle End Sub
And finally add the following line to the code that handles how your application closes:
Note: If you have enabled the application framework in your project then you can check the 'Save My.Sttings on shutdown' and this will be taken care of automatically.
So you can see that your end user can now select a style and the application will remember it from instance to instance of your program being run.
If you want to add that extra element of wow to your program you could check to see if users have office installed and check to see which office theme is currently in use. This will involve reading the registry. The settings that you would need to check in the registry are:
HKEY\_CURRENT\_USER\\Software\\Microsoft\\Office\\12.0\\Common (for office 2007) HKEY\_CURRENT\_USER\\Software\\Microsoft\\Office\\14.0\\Common (for office 2010)
You will need the value of the key called 'Theme' which will be set to one of the following:
There are two other areas where I like to give extra control to the end-user. If you're a fan of the C1SuperTooltip then you'll know how versatile this control can be. Hopefully though as your users become more familiar with your program they'll have less need of tooltips. After a while they might even start to find them a nuisance. C1SuperTooltip has an 'Active' property which by default is set to true (meaning of course that the tooltip will be displayed). By associating a setting with this property you can provide a means by which your end user can toggle the visibility of all tooltips.
Note: The new C1SuperError provider utilizes the C1SuperTooltip to draw itself when required. Obviously you don't want to allow your end user to turn errors off, so if you're going to use the new error provider then add an extra C1SuperTooltip to your form to act as the host for the error provider and DO NOT link its 'Active' property to your setting.
Incidentally, the C1Ribbon control and the C1InputPanel generate their own tooltips. To give the end user control over these you need to bind their 'Active' properties to the user setting you choose to use for this. The property can be accessed under the ToolTip Settings, see below.
C1DynamicHelp is also a good candidate for giving your end users extra control. When they are getting to know your program it's invaluable, but after a while it can become a hindrance, taking up valuable screen space that they might wish to use in another way. Again, binding the visibility of C1DynamicHelp to a setting over which the end user can exercise a choice makes perfect sense.
So far so good. Your end-user now has a level of control over your program, and they are beginning to realize that you've put a great deal of thought into making their experience that much better. However these settings are stored in an XML file that is tightly linked to the version number of your program. What happens when you release a new version? Are your users going to have to spend time reconfiguring things to the way they had them set in the previous version?
Fortunately, you can make use of a feature that's not particularly well documented. The project settings have an Upgrade() function that will copy the user settings from the configuration xml of a previous version to the new one. To make this process as seamless as possible, create a new settings property (call it something like 'SettingsUpgraded' of type Boolean.) Again it needs to be a User property and the default value needs to be set to False. In the sub main of your project add the following:
#If DEBUG Then #Else If Not My.Settings.SettingsUpgraded Then Else My.Settings.Upgrade() My.Settings.SettingsUpgraded = True End If #End If
Now when you realease a new improved version of your program (exploiting all the new goodies that ComponentOne has provided since the last version you released) your program will upgrade your end users preferences seamlessly and you'll look all the more professional.
-The content of this blog post was written by Dom Sinclair.