Simple custom ownerdraw button
-
I have a class myButton:Button { myButton(object obj) { //... } protected void override OnPaint(PaintEventArgs ev) { // code } } What i want: I have a form with a simple button. When i enter the event_click this button i create a myButton control object that i want to be drawn somewhere on the form. The reason why i need a custom control is that i want the myButton obj to contain the object that i send to the constructor. How do i draw this button to the form, what do i call and so forth? The properties i want to set for this myButton is that it is flat for now.. To this myButton i want to register the double_click event. Have searched the internet but i am a bit confused, i thought i understood but nothing draws. Please som help!
-
I have a class myButton:Button { myButton(object obj) { //... } protected void override OnPaint(PaintEventArgs ev) { // code } } What i want: I have a form with a simple button. When i enter the event_click this button i create a myButton control object that i want to be drawn somewhere on the form. The reason why i need a custom control is that i want the myButton obj to contain the object that i send to the constructor. How do i draw this button to the form, what do i call and so forth? The properties i want to set for this myButton is that it is flat for now.. To this myButton i want to register the double_click event. Have searched the internet but i am a bit confused, i thought i understood but nothing draws. Please som help!
babbelfisken wrote:
protected void override OnPaint(PaintEventArgs ev) { // code } }
You'll be wanting to look at ev.Graphics - the Graphics object. This will allow you to manually draw the button. For example:
ev.Graphics.DrawRectangle(Pens.Black, this.ClientRectangle);
But it gets more complex - double buffering, multiple states (enabled, disabled etc..). Is that a good starting point? Eitsop