Creating a custom control that count the klicks on a button

pragmatiker

New member
Joined
Oct 13, 2005
Messages
4
Programming Experience
Beginner
Hello,
I want to create a custom button control. That button should have all functions fromt he normal button, but should additional count the Clicks on the button
I've created a ne class library and inherit the Forms.Button.

But now I have no idea how to code that the new Button count the Klicks.
Anybody an idea or some code?
Thanks!
 
VB.NET:
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] MyButton[/SIZE][INDENT][SIZE=2][COLOR=#0000ff]Inherits[/COLOR][/SIZE][SIZE=2] Button
[/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] pClicks [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0

[/SIZE][SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Overrides[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] OnClick([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs)[INDENT]pClicks += 1

[/INDENT][/SIZE][INDENT][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].OnClick(e)
[/SIZE]
[/INDENT][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ReadOnly[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property[/COLOR][/SIZE][SIZE=2] ClickCount() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer

[/COLOR][/SIZE][INDENT][SIZE=2][COLOR=#0000ff]Get

[/COLOR][/SIZE][INDENT][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] (pClicks)
[/SIZE]
[/INDENT][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Get
[/COLOR][/SIZE]
[/INDENT][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property
[/COLOR][/SIZE]
[/INDENT][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE]

Compile your solution, right click on your toolbox to select the dll in you 'bin' folder. You new button is ready to work and can be dragged on your windows form.;)
 
Back
Top