Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to create a simple control (button) without inherits from Button Class in C# or VB.NET?
Posted
Comments
CHill60 1-Sep-15 9:48am    
You could use a PictureBox and handle the click event in that, or write a complete control from scratch.
What are you actually trying to do?
Ma'd Saeed 1-Sep-15 10:00am    
I need to create a simple button from zero like this:
public class myButton
{

}

instead of:

public class myButton:Button
{

}
Sergey Alexandrovich Kryukov 1-Sep-15 11:47am    
PictureBox is probably the worst option, if one needs to show some visual feedback, which is animated. It should be derived from Control class, with some graphic rendering.
I'll answer the question in detail if the inquirer explains what is "Button", exact full type name. The solutions, say, for System.Windows.Forms and WPF will be very different.
—SA

As you are trying to start completely from scratch, probably the best way is to observe how the .NET Button class was written in the first place.

The source code for that can be looked on the .NET Reference Source[^] site.

Give it a go and if you hit problems come back with a specific question
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Sep-15 11:48am    
Good idea, a 5, but the idea of using PictureBox is bad.
Besides, we don't really know if the inquirer uses System.Windows.Forms or something else, but reference source could be found for something else.

And finally: a really practical ad-hoc specialized button-like custom control can be orders of magnitude simpler that this fully-fledged Micrsoft code.

—SA
Maciej Los 1-Sep-15 15:34pm    
5ed!
Another option is to create custom button from System.Windows.Forms.Control. Please, see my answer.
Ma'd Saeed 13-Sep-15 10:11am    
thanks brother, but I don't need to inherit my control from an existing control
Hi
Use .Net Reflactor to decompile button class. This will help you in writing your own class.


http://www.red-gate.com/dynamic/products/dotnet-development/reflector/download[^]
 
Share this answer
 
You can create custom button which inherits from System.Windows.Forms.Control[^].
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900