nearlogic.com

a programmer’s blog

Gradient Button Control

Since there seems to be people around who still use VB6, I thought I’d post some more of my stuff.  Here is a button control that can add a nice touch to some apps.  This control is completely owner drawn, and uses code from Carles P.V. (on planetsourcecode.com) and Karl Peterson. This control can also act as a check button, or as a panel (container) object.  I don’t think I need to say too much else about it, apart from the interface description:

Properties:

  • BackColor: The backcolor will be seen on the border of the control if BorderWidth > 0 or the control has focus.
  • BevelWidth: The number of pixels used for the Bevel (3D effect) of the button.
  • BorderWidth: The number of pixels for the solid color border (BackColor).
  • Cancel: Indicates whether the button is the Cancel button on the form (reacts to the Esc key).
  • Caption: You should know what this is.
  • Color1: First color of the gradient pattern.  Darker than Color2 for 3D effect.
  • Color2: Second color of the gradient pattern.  Lighter than Color1 for 3D effect.
  • Default: indicates whether the button is the Default button on the form (reacts to the Enter key).
  • DownColor1: First color of the gradient pattern when the mouse button is down.  Lighter than DownColor2 for 3D effect.
  • DownColor2: Second color of the gradient pattern when the mouse button is down.  Darker than DownColor1 for 3D effect.
  • FontEffect: indicates which effect is applied to the caption text.  Options: None, Outline, Shadow, Emboss.
  • ForeColor: Color used for Caption.
  • ForeColor2: Color used for FontEffect on the Caption.
  • HoverColor1: First color of the gradient pattern when the mouse is over the button.  Darker than HoverColor2 for 3D effect.
  • HoverColor2: Second color of the gradient pattern when the mouse is over the button.  Lighter than HoverColor1 for 3D effect.
  • Mode: Sets behaviour of control.  Options: Command Button, Check Box, Panel
  • Picture: Image that is centered on control.  Black is transparent (change picButton.ForeColor inside ctl file to change maskcolor).
  • RepeatInterval: Sets interval (milliseconds) for MouseDownRepeat event. (Useful for repeated command while button is held down)
  • Value: indicates position of button when in Check Box mode.

Image:  If you have any style at all, you can do much better than this.

Events:

  • MouseDownRepeat: Event fires when button is held down and RepeatInterval > 0.  Event repeats on Interval timer until MouseUp occurs.
  • MouseOff: Event fires when the mouse cursor leaves the controls boundaries (after final MouseMove event)
  • MouseOnTimer: Event fires repeatedly while mouse cursor is over control.  Timer interval = 20ms.

Download the control source code and sample app here (30kB)

No comments yet. Be the first.

Leave a reply

Banner