Click here to Skip to main content
13,256,841 members (51,458 online)
Click here to Skip to main content
Add your own
alternative version


41 bookmarked
Posted 15 Dec 2004

A Multi Gradient Button

, 15 Dec 2004
Rate this:
Please Sign up or sign in to vote.
Button that allows multiple gradients defined at design time.

Sample Image - gradbutton.jpg


First I'd like to thank David Preece for his rainbow button article. Great job, David and it got me thinking! The control has all the features of a regular button and is fully customizable at design time through the properties editor. It also uses a collection of colors (DLL provided) to store the colors.


Why limit the colors to five? So, here is the results of that! A multi colored (minimum of two) gradient button.

How to use the Code

MTMultiGradiantButton can be used in any C# Windows project.

First, add the MTCollections.dll to your project as a resource. Next add MTControls.dll to the toolbox of your Visual Studio or Sharp Develop (the complier I used to create the control). Select the MTMultiGradiantButton control from the file. Then drag and drop the button from the toolbox onto a form. Or you can instantiate the button yourself like this:

private MTControls.MTButtons.MTMultiGradiantButton mTMultiGradiantButton1;
this.mTMultiGradiantButton1= new MTControls.MTButtons.MTMultiGradiantButton();


or use a different constructor that takes two colors.

private MTControls.MTButtons.MTMultiGradiantButton mTMultiGradiantButton1;
this.mTMultiGradiantButton1 = new MTControls.MTButtons.MTMultiGradiantButton(
System.Drawing.Color.Black, System.Drawing.Color.Lime);

Next, just add the colors you want in two ways:

Using the properties editor, select the Colors property of the button and add your colors through the interface or programmatically add your colors like this:

// this creates a rainbow button with 6 colors
this.mTMultiGradiantButton3 = 
       new MTControls.MTButtons.MTMultiGradiantButton();
      (System.Byte)(255)), ((System.Byte)(128)), ((System.Byte)(0))));

Special interest in the code

Activating the ability to use the MTColorCollection in the code was interesting. I needed a dynamic array that would hold color values and be available to set through the property interface at design time. I created the MTColorCollection class that would hold the colors by deriving it from CollectionBase but getting the property interface to use it was as simple as creating a read only property for the MTColorCollection class.

private MTColorCollection m_clrColors = new MTColorCollection();
// This is for the properties interface so you can add colors at design time
// it tells the interface to use the follows MTColorColletion Colors property
// as a template to create the interface for adding colors to the control

public MTColorCollection Colors
    return m_clrColors;

Finishing up

So go ahead and check out the code. I didn't include project files since I used SharpDevelop and they would be useless to you, Visual Studio .NET users.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Questionthe source code for MTCollections Pin
zuaretd24-Oct-06 4:37
memberzuaretd24-Oct-06 4:37 

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
Web03 | 2.8.171114.1 | Last Updated 15 Dec 2004
Article Copyright 2004 by marktoth
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid