Click here to Skip to main content
13,004,203 members (79,658 online)
Click here to Skip to main content
Add your own
alternative version


88 bookmarked
Posted 24 Feb 2010

GlowButton - A Glowing Button Control

, 28 Mar 2010
Rate this:
Please Sign up or sign in to vote.
A simple media control button

Just a Quickie...

Recently I came across the KMP Player software, and was looking over some of the graphic elements (and if you want to see some really good graphics work, I recommend you check it out). One of the elements that I need for a project was a simple glowing button control, used for the player controls, nothing too fancy, just an image that changes color and glows when hovered.

Getting an image to change color is rather trivial, it is done by modifying the color matrices of an ImageAttribute:

private void DrawColoredImage(Graphics g, Image img, Rectangle bounds, Color clr)
     using (ImageAttributes ia = new ImageAttributes())
         ColorMatrix cm = new ColorMatrix();
         // convert and refactor color palette
         cm.Matrix00 = ParseColor(clr.R);
         cm.Matrix11 = ParseColor(clr.G);
         cm.Matrix22 = ParseColor(clr.B);
         cm.Matrix33 = ParseColor(clr.A);
         cm.Matrix44 = 1f;
         // set matrix
         // draw
         g.DrawImage(img, bounds, 0, 0, img.Width, 
                     img.Height, GraphicsUnit.Pixel, ia);

The ParseColor in the example code simply converts byte to float values.


Getting the glow effect is also done using the ImageAttributes class. The image is first inflated, then the color palette and Alpha values are altered, then the clean image is drawn overtop. All this is done by first drawing the control elements into a buffer bitmap:

private void DrawButton()
    if (this.Image == null)

    Rectangle bounds = new Rectangle(0, 0, this.Width, this.Height);
    Rectangle imageBounds = GetImageBounds(bounds, this.Image);

    // draw into a buffer
    using (Graphics g = Graphics.FromImage(_bmpBuffer))
    // draw the buffer
    using (Graphics g = Graphics.FromHwnd(this.Handle))
        DrawImage(g, _bmpBuffer, bounds);

The control comes with most of the properties exposed, like various color states, and optional focus mask and border. Here's a list of the properties:

  • Checked: Checkbox state
  • CheckedBorderColor: The checked border color
  • CheckStyle: Checkbox style
  • FocusedMask: Draw a focused mask
  • ImageDisabledColor: The image disabled color
  • ImageFocusedColor: The image focused color
  • ImageGlowColor: The border glow color
  • ImageHoverColor: The image hover color
  • ImagePressedColor: The image pressed color
  • ImageGlowFactor: Glow factor depth
  • FocusOnHover: Focus on button hover


  • 24th February, 2010: Initial post
  • 27th March, 2010: Article screen shot and source code


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

John Underhill
Network Administrator
Canada Canada
Network and programming specialist. Started in C, and have learned about 14 languages since then. Cisco programmer, and lately writing a lot of C# and WPF code, (learning Java too). If I can dream it up, I can probably put it to code. My software company, (VTDev), is on the verge of releasing a couple of very cool things.. keep you posted.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
majid torfi2-Nov-14 3:00
membermajid torfi2-Nov-14 3:00 
GeneralMy vote of 5 Pin
Kanasz Robert27-Sep-12 8:39
mvpKanasz Robert27-Sep-12 8:39 
GeneralMy vote of 5 Pin
tolw6-Jun-11 0:17
membertolw6-Jun-11 0:17 
GeneralSet BackColor as Transparent! Pin
w.y.zhang31-Mar-10 22:22
memberw.y.zhang31-Mar-10 22:22 
GeneralUpdated Pin
Steppenwolfe28-Mar-10 5:43
memberSteppenwolfe28-Mar-10 5:43 
GeneralNice but you contradict yourself... Pin
je_gonzalez25-Feb-10 13:03
memberje_gonzalez25-Feb-10 13:03 
GeneralRe: Nice but you contradict yourself... Pin
Steppenwolfe25-Feb-10 14:51
memberSteppenwolfe25-Feb-10 14:51 
GeneralNew Version Pin
Steppenwolfe25-Feb-10 10:18
memberSteppenwolfe25-Feb-10 10:18 
Generalnice control Pin
Member 413085925-Feb-10 0:03
memberMember 413085925-Feb-10 0:03 
GeneralRe: nice control Pin
Steppenwolfe25-Feb-10 3:01
memberSteppenwolfe25-Feb-10 3:01 
Generalnice control but... Pin
DanielGreen24-Feb-10 21:14
memberDanielGreen24-Feb-10 21:14 
GeneralCool Pin
Johnny J.24-Feb-10 19:30
memberJohnny J.24-Feb-10 19:30 
GeneralRe: Cool Pin
Steppenwolfe25-Feb-10 3:00
memberSteppenwolfe25-Feb-10 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170627.1 | Last Updated 28 Mar 2010
Article Copyright 2010 by John Underhill
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid