Jane Panda
Jane Panda

Reputation: 1671

How can I add a border, or otherwise emphasize a 3d-styled button?

I have a set of three buttons labeled 1, 2 and 3 for a touchscreen application interface.

When the user clicks one, it should be "selected" and have some kind of obvious change that shows this.

When using a flat button style I can do this with a border, however it seems this does not apply to Buttons with the default/3d style.

I've noticed the backcolor can be set, however this only seems to apply plain colors, which generally looks pretty ugly.

Is there a way I can add something like a border or emphasize the "selected" 3d-styled button in another way? Is there a better control for this purpose that works well with touch screen interfaces?

Upvotes: 1

Views: 1361

Answers (3)

Jane Panda
Jane Panda

Reputation: 1671

Well, I was able to add an inset border using:

class BorderButton : Button
{
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        e.Graphics.DrawRectangle(new Pen(Color.Black, 6), this.DisplayRectangle);
    }
}

It seems however the paint event can't draw outside of the button's borders, so an outset one wouldn't be possible using this technique.

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 941635

A button cannot indicate a "selected" state, it can only have the focus. Which is of no use in a touch screen app.

What you want is a CheckBox instead. Which also supports looking like a button, set its Appearance property to Button. You can further tinker with the way it looks by modifying the FlatStyle property. By setting it to Popup for example it acquires a 3D-look when checked.

Upvotes: 2

Benno
Benno

Reputation: 2534

I've had the same problem and now always use a label instead. This way you can catch the on_click or mousedown events and apply background colours or images as if it was a button.

Upvotes: 0

Related Questions