Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] C# custom button

Started by pim Apr 10, 2005 at 4:49 PM 2 replies 900+ views
Original Post
pim
pim
Hi! I'm trying to create my own custom button but I just ran into a couple of problems. The button is an image button with different images for different states, and the images should be able to be transparent. I've tried a couple of approaches, but none of them works the way I want. A - Inherit from Control This method works ok except it doesn't handle tabbing away from the control right. B - Inherit from Button I override onpaint to prevent it from painting the normal button look, but then I loose the Paint event.. and I'm not able to call it from onpaint either C - Inherit from ButtonBase I don't know why, but this approach crashes in OnPaint :/ any suggestions?
turnpast
turnpast
Quote:
Original post by pim
A - Inherit from Control
This method works ok except it doesn't handle tabbing away from the control right.

And you set TabStop to true and TabIndex to a unique index?

Quote:

B - Inherit from Button
I override onpaint to prevent it from painting the normal button look, but then I loose the Paint event.. and I'm not able to call it from onpaint either

One way to propogate paint events from on overriden OnPaint() is to call base.OnPaint().

Quote:

C - Inherit from ButtonBase
I don't know why, but this approach crashes in OnPaint :/

Hummm.

You could also try using PictureBox to avoid having to overwrite OnPaint, just capture the mouse events and change the Image property.
pim
pim
Nevermind... I found out of it.. I ended up inheriting from Control.. I just needed to call this.Focus() when the button was clicked to make the focus-code work correctly..
pim
pim
turnpast:
The problem with using base.OnPaint when inheriting from a button, is that the paint code is called too, not just the event handler...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.