ColorReliefButton

crb1.gif 

Summary for ColorReliefButton:

My idea was to create a button that can be used as a colourful decoration for any application.

The look of the ColorReliefButton can be determined by changing property values. The main attraction should be a cool look (Relief) of the controls text. Like this almost any font (TrueTyp) can be used to decorate a button and there is no need to use bitmaps.

Realisation:

Derive a Class
ColorReliefButton derives from System.Windows.Forms.Button.

Added custom properties:
To customise the look of the button I added the following properties:
  1. BrushFocusScaleX
    Influences the PathGradientBrush by mixing the Colors in x direction (Values 0-1f)
  2. BrushFocusScaleY
    Influences the PathGradientBrush by mixing the Colors in y direction (Values 0-1f)
  3. ButtonColor
    Surface color for the Button
  4. DisplayLetterSpacing
    Enabling this property will draw a red rectangle around every character of the text. Can be used to get visual information about the current font.
  5. LetterInterspace
    Property to add space (pixel) between the characters of the text. Can be used for fonts that ships in with few space between the character.
  6. FrameWidth
    Property to set the width of the buttons 3D frame.
  7. TextColor1,2
    Textcolors used when the button is out of focus.
  8. TextColor3,4
    Textcolors used when the mouse is on the button.
  9. TextColor5,6
    Textcolors used when the button is pressed.
  10. TextLightStyle
    Can be switched between two values (1,2). Determines how the color is mixed by the PathGradientBrush.
    1. Means one Brush for the whole text.
    2. Means one Brush for every character (equal for all, but splitted on every char).

crb2.gif
Added method overrides for:

  1. OnPaint
    Calls the 2 methods (DrawControl and DrawControlStringRelief) to draw the control and the text relief (see later). Depending on the members bMouseOver and bPushed the calls will be given other parameters.



  2. OnMouseUp
    Sets the member bPushed to true.
  3. OnMouseDown
    Sets the member bPushed to false and "invalidates" the control to be redrawn by calling the method Invalidate.

Added eventhandlers for:

  1. MouseEnter Event
    Sets the member bMouseOver to true and "invalidates" the control to be redrawn by calling the method Invalidate.

  2. MouseLeave Event
    Sets the member bMouseOver to false and "invalidates" the control to be redrawn by calling the method Invalidate.

Added 2 methods to do the graphic part:

  1. DrawControl draws the buttons user interface in 3D style.
  2. DrawControlStringRelief draws the Button's text in "Relief Style"
    This method works depending on all the custom properties mentioned above.

Disabled some of the inherited Properties:
For not having to much properties in the property window I disabled several properties that are no longer of use for this control (all background and image properties).

Conclusion:

There is much effect without a huge amount of work.

Up Next
    Ebook Download
    View all
    Learn
    View all