Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.47/5 (3 votes)
Hello.

I want to create a custom checkbox control for a windows forms application.
To do this I tried to inherit from a button control and placed a transparent picturebox on the button. I want the control to react on focus and hower events like the button control does, but not only if the mouse is on the button but also if the mouse is on the picturebox. The control shall behave like a unit, not like a button with a picture box.

Thanks for your help.
Posted
Comments
Sergey Alexandrovich Kryukov 24-Apr-15 9:41am    
This is not so easy, but quite doable. Your biggest mistake here is using a PictureBox. Don't do it. Render graphics yourself.
—SA
Maciej Los 24-Apr-15 15:38pm    
Not clear what you're asking for... ;(
Why to replace existing control if it's already exists??? If you want to extend some methods/ properties, use base class (CheckBox)!
BillWoodruff 24-Apr-15 17:17pm    
Please say more about what your goal is here. What custom functionality do you want to have that requires that you create a custom CheckBox ? Do you want the CheckBox to be two-state or three-state ?
Georg Newton 27-Apr-15 2:32am    
You're right, maybe I should tell you about the requirements. The checkbox is to evaluate tests. Therefore it is supposed to have three states: unknown(when you could not perform the test), passed and failed. In order to fit to the rest of the software, I would like to use the symbols I used there.

1 solution

Please see my comment to the question.

Please see my past answers:
Append a picture within picturebox[^],
draw a rectangle in C#[^],
How do I clear a panel from old drawing[^].

Other problems could be solved as you face them, but it's still better to make a good plan.

—SA
 
Share this answer
 
Comments
Maciej Los 24-Apr-15 15:39pm    
Short and to the point!
Sergey Alexandrovich Kryukov 24-Apr-15 15:42pm    
Thank you, Maciej.
—SA
Maciej Los 24-Apr-15 15:47pm    
Sergey, have you seen my comment to the question? I do not understand why people wantd to "replace" existing controls. They have to extend its methods and properties instead creating completely new one. Am i right or am i wrong? I'm wondering your opinion...
Sergey Alexandrovich Kryukov 24-Apr-15 16:12pm    
I don't know, there are cases when it makes sense, I think.

The problem is different: people tend to decorate (or even clutter with decorations) instead of inventing really advanced behavior. This is just visual garbage. So, on one pole, a delicate touch on individual recognizable design (but then, on all elements, not just one, in a really artful, coherent ways). That could be very delicious design, and yet touching controls just a bit, some specially chosen colors and highlights. On another pole, you can develop something really innovative, but that should be based on really rich behavior, not just look. For example, I decided to develop joystick control and found it very efficient (progressive scale in speed of the controlled machine, and the like). And of course I decided to design adequate UI control for that. I don't want to say my work was really good (most likely, not quite), but this is something non-trivial, to show all those degrees of freedom, providing proper fallback control behavior when the joystick is not physically present, and so on. There are many cases like that.

And there are too many people who are doing not this and not that, but who knows what. I think they just waste time. Or maybe some don't waste time, because they spend this time learning things on their own mistakes. If they do, it's also not too bad. Eventually, based on their negative and positive experience, they might start inventing really good stuff, who knows...

—SA
Maciej Los 24-Apr-15 16:17pm    
Ha! I got motto: "Don't waste your time to decorate UI. Too much `decoration` will kill you" ;)

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