|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionI have written a number of applications and always been a little disappointed at how drab they look using the standard VS controls. I had been looking for an easy way for brightening up these apps and in the end resorted to writing my own button control based on the "The Aqualizer Strikes Back!" work found on the Code Project site. Using this, control bitmaps are created "on the fly" according to the attributes of the control. Colour, Height, Width, Font Size and Text. The slow rendering speed of the graphics is negated by using cached bitmaps. For each button two Png files are produced. One is the colour of the button and the other which is clear and is used when the mouse hovers over the button and when the button is disabled. Using this control you gain the advantages of both options - flexible image generation and - speed. Using the Control in your own ApplicationsThe control can be used as a normal button control "as is". Simply add the project to your solution and you can add the control to your forms. Remember the aquabutton control must be compiled before it can be added to the form in the form editor. Use the propertiesButtonText, ButtonColour, FontSize and TextColour to set the text and colours of the button.Points of InterestNew Properties on the ButtonUsing VS 2003 I spent quite some time trying to make Text and ForeColor do my bidding. For one reason or another I found these to be unreliable and decided in the end to use my own properties. HenceButtonText, ButtonColour, FontSize and TextColour are used.Making the Button's Text Property viewable on the form editorTo add my own properties to the Aqua Button Control I found it useful to use the Description, Default Value and the Browsable attributes. The sample below shows how this is. Useful tips in setting the properties can be given in the description field.[Description("The text visible on the control. Use \\n for line breaks")] [DefaultValue("Not Set") [Browsable()> public string ButtonText { set { base.Text="not set"; initialise(); m_text=value; redrawButton(); } get { return m_text; } } Deriving your own Button ClassesIf in a moment of madness, if you feel inclined to base your own control on the Aqua Button control, it is perfectly possible to override the CreateImage() method to produce alternative designs (e.g. diamonds, emeralds etc). The helper classes for the graphics are are provided for doing all of this. You may have to make some of them public.To understand how to do this, just use the class provided to get yourself started. For more information about how the algorithms work I suggest you take a look at the excellent "Aqualiser Strikes Back" article. In overriding CreateImage() be sure to cache the images in the same way as the base class or performance will suffer. private void createBaseImages() { /* Call the overrideable CreateImage routines to get the bitmaps/images */ m_image=CreateImage( m_buttonColour ); m_nofocusImage=CreateImage( Color.White ); this.Image = m_image; } Limitations
FeedbackI use this control a lot in my own applications as it brightens up the UI dramatically. I realise that the control is not a completely finished and has shortcomings (not serious ones hopefully). Feedback is gratefully accepted and where fitting will be incorporated in later versions of the control.
|
||||||||||||||||||||||