Click here to Skip to main content
Licence 
First Posted 13 Jun 2002
Views 96,624
Downloads 123
Bookmarked 17 times

A clickable button

By Chris Sells | 13 Jun 2002
An immensely handy clickable button.
6 votes, 40.0%
1

2

3

4
9 votes, 60.0%
5
3.40/5 - 47 votes
μ 3.92, σa 3.59 [?]

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


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

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 Pinmemberio.akimov7:49 29 Jul '10  
GeneralWPF PinmemberAdrian Schröder1:24 14 Sep '09  
GeneralMy Search Is Complete! PinmemberFelix De Herrera14:50 15 Jul '09  
GeneralPlease ... Pinmembermbaocha13:42 6 May '09  
GeneralPlease anybody help me for how to sending Http request and how to get response of http for c#.Net Pinmemberdudhat6:48 8 Feb '08  
GeneralLOL Pinmembersk8er_boy28722:41 7 May '07  
GeneralNow your in trouble PinmemberGiles13:46 21 Oct '02  
Generalhahahahahahahahahha PinmemberSwinefeaster0:03 7 Jul '02  
GeneralSome industry perspective PinmemberMike Sax8:23 25 Jun '02  
GeneralRe: Some industry perspective PinadminDavid Cunningham18:45 25 Jun '02  
GeneralRe: Some industry perspective PinmemberNishant S19:09 25 Jun '02  
GeneralRe: Some industry perspective PineditorBrian Delahunty3:26 5 Oct '02  
GeneralException raised when started PinmemberPatko23:39 17 Jun '02  
GeneralRe: Exception raised when started PinmemberRob van der Veer3:25 8 Jun '04  
GeneralImprovement Suggestion PinmemberEd Gadziemski4:25 15 Jun '02  
QuestionCan you please post code for this is VB. I have need for in project Pinmemberzjouing23:22 14 Jun '02  
GeneralCool! PinmemberMazdak20:05 14 Jun '02  
GeneralNice. But can PinsupporterChris Losinger10:29 14 Jun '02  
GeneralWOW!!!! PinmemberCWizard10:14 14 Jun '02  
GeneralRe: WOW!!!! PinmemberNebuGranny10:55 29 Mar '04  
QuestionI can't get it to work? PinmemberRoger Allen7:37 14 Jun '02  
GeneralFun PinmemberDieder5:31 14 Jun '02  
GeneralRe: Fun PinmemberMarc Richarme10:10 14 Jun '02  
GeneralAnother fun idea (article suggestion) PinmemberBlack Cat5:02 14 Jun '02  
GeneralYou're soooooooo evil PinsubeditorJames T. Johnson22:48 13 Jun '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web03 | 2.5.120210.1 | Last Updated 14 Jun 2002
Article Copyright 2002 by Chris Sells
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid