Skip to main content
Email Password   helpLost your password?
Sample Image - Sample Image.jpg

Introduction

I have written a number of applications and have 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 CodeProject 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 Applications

The 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 properties ButtonText, ButtonColour, FontSize and TextColour to set the text and colours of the button.

Points of Interest

New Properties on the Button

Using 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. Hence ButtonText, ButtonColour, FontSize and TextColour are used.

Making the Button's Text Property Viewable on the Form Editor

To 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(true)]
public string ButtonText
{
    set
    {
        base.Text="not set";
        initialise();
        m_text=value;
        redrawButton();
    }

    get
    {
        return m_text;
    }
}

Deriving Your Own Button Classes

If 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 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 overridable CreateImage routines to get the bitmaps/images */
    m_image=CreateImage( m_buttonColour );
    m_nofocusImage=CreateImage( Color.White );
    this.Image = m_image;
}

Limitations

Feedback

I use this control a lot in my own applications as it brightens up the UI dramatically. I realize that the control is not 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.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralHow can i get a click event? Pin
alfredopfr
11:53 30 Jun '09  
GeneralCan the corner radius be adjusted? Pin
Member 2275006
6:40 10 Mar '09  
GeneralBackColor Transparent problem !!! Pin
honma
15:13 21 Jan '09  
GeneralIs this can use for smart device? Pin
Chanuri
20:24 29 Dec '08  
GeneralRe: Is this can use for smart device? Pin
Rad1cal
7:07 7 Jan '09  
GeneralHow to change shape of the button? Pin
sarvind1907
3:26 5 Aug '08  
GeneralCan the text be made brighter? Pin
DutchJohn
10:55 11 May '08  
GeneralRe: Can the text be made brighter? Pin
aberg
10:47 6 Jul '08  
GeneralCannot Download or view Screenshots Pin
Sukhjinder_K
21:00 8 Dec '07  
GeneralHow to asign short cut key Pin
sudhir paliwal
5:10 22 Oct '07  
GeneralRe: How to asign short cut key Pin
Rad1cal
5:11 29 Nov '07  
GeneralCan Aqua Buttons be used with Web Form?? Pin
B-RadG
11:10 18 Jul '07  
GeneralRe: Can Aqua Buttons be used with Web Form?? Pin
Rad1cal
7:44 24 Jul '07  
Generalvery nice Pin
Alexandros200510
0:47 20 Oct '06  
GeneralRe: very nice Pin
Rad1cal
13:40 20 Oct '06  
Questionvery cool Pin
wurakeem
3:41 17 Oct '06  
AnswerRe: very cool Pin
Rad1cal
6:17 17 Oct '06  
AnswerRe: very cool Pin
Rad1cal
1:10 18 Oct '06  
GeneralVery nice visual Pin
Lutz Morrien
0:36 17 Oct '06  
GeneralWhich Visual Studio was that?... Pin
Petru66
5:26 17 Oct '06  
GeneralRe: Which Visual Studio was that?... Pin
Rad1cal
6:15 17 Oct '06  
GeneralRe: Which Visual Studio was that?... Pin
Petru66
6:23 17 Oct '06  
GeneralRe: Which Visual Studio was that?... Pin
Rad1cal
1:11 18 Oct '06  
GeneralRe: Which Visual Studio was that?... Pin
Rad1cal
1:07 18 Oct '06  


Last Updated 18 Oct 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009