Click here to Skip to main content
Click here to Skip to main content

A clickable button

By , 13 Jun 2002
 

Welcome to ClickableButton!

As useful and as popular as Chris Maunder's "An unclickable button" article and class is, I thought that a clickable button might also be useful. While my ClickableButton class is implemented specifically for .NET, the very same techniques can be used in nearly every object-oriented windowing library.

Sample

Here's a sample of using the ClickableButton class. Notice that we've handled the Click event to show a message box of appreciation:

Usage

To use ClickableButton, simple add it to your form, either via the WinForms designer or manually, setting properties as appropriate:

class Form1 : Form {
  ClickableButton button1;
  ...
  void InitializeComponent() {
    this.button1 = new ClickableButton();
    ...
    this.button1.Location = new System.Drawing.Point(24, 24);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(200, 120);
    this.button1.TabIndex = 0;
    this.button1.Text = "Click Me!";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    ...
    this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1});
    ...
  }
}

Behavior

Notice from the sample application that the ClickableButton will show itself as a shadowed square with a text label. When the user uses the mouse to click on the ClickableButton, it will take on a depressed look 'n' feel and fire the Click event, which a hosting program can handle. For example, the sample handles the Click event like so:

void button1_Click(object sender, EventArgs e) {
  MessageBox.Show("Ohhh... That's nice.", "ClickableButton Clicked");
}

Implementation

My ClickableButton class derives from the base class System.Windows.Forms.Button class and adds absolutely nothing:

public class ClickableButton : System.Windows.Forms.Button
{
}

Issues

While this button is fairly functional, it's not nearly as fun as ChrisM's unclickable button. Potential ways to make it more fun include:

  • Calling the user nasty names.
  • Formatting "c:".
  • Switching the user interface language to Spanish.
  • Spawning a virus.
  • Overheating the CPU.
  • Resetting the user's MineSweeper high scores.

License

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

Chris Sells
Web Developer
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralRe: Some industry perspectivememberNishant S25 Jun '02 - 18:09 
GeneralRe: Some industry perspectiveeditorBrian Delahunty5 Oct '02 - 2:26 
GeneralException raised when startedmemberPatko17 Jun '02 - 22:39 
GeneralRe: Exception raised when startedmemberRob van der Veer8 Jun '04 - 2:25 
GeneralImprovement SuggestionmemberEd Gadziemski15 Jun '02 - 3:25 
QuestionCan you please post code for this is VB. I have need for in projectmemberzjouing14 Jun '02 - 22:22 
GeneralCool!memberMazdak14 Jun '02 - 19:05 
GeneralNice. But canmemberChris Losinger14 Jun '02 - 9:29 
GeneralWOW!!!!memberCWizard14 Jun '02 - 9:14 
GeneralRe: WOW!!!!memberNebuGranny29 Mar '04 - 9:55 
QuestionI can't get it to work?memberRoger Allen14 Jun '02 - 6:37 
GeneralFunmemberDieder14 Jun '02 - 4:31 
GeneralRe: FunmemberMarc Richarme14 Jun '02 - 9:10 
GeneralAnother fun idea (article suggestion)memberBlack Cat14 Jun '02 - 4:02 
GeneralYou're soooooooo evilsubeditorJames T. Johnson13 Jun '02 - 21:48 
GeneralRe: You're soooooooo evilmemberyannc13 Jun '02 - 23:39 
GeneralNo future.memberfnicola13 Jun '02 - 21:31 
GeneralRe: No future.memberleppie14 Jun '02 - 4:23 
GeneralRe: No future.memberChris Losinger14 Jun '02 - 10:23 
GeneralRe: No future.memberrobinds19 Jun '02 - 3:49 
GeneralRe: No future.memberChris Losinger19 Jun '02 - 3:54 
GeneralRe: No future.memberSander198117 Oct '03 - 2:19 
GeneralSimple & ConsisememberNorm Almond13 Jun '02 - 21:33 
GeneralRe: Simple & Consisememberpeterchen14 Jun '02 - 0:04 
GeneralSuperb!memberVernero Cifagni13 Jun '02 - 21:12 
GeneralROTFLMAOmemberNish - Native CPian13 Jun '02 - 21:11 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 14 Jun 2002
Article Copyright 2002 by Chris Sells
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid