views:

295

answers:

1

Hey guys,

I have a button that I want to make default, but without the border thing around the button. Is this possible to do?

Thanks.

+1  A: 

The visual cue comes as standard if you set the default button. You could, however, do something with key-preview, capturing carriage-return and performing the required action(s) necessary. To give a C# example (same concepts apply to VB.NET):

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Button btn1, btn2;
    using(Form form = new Form {
        Controls = {
            (btn1 = new Button { Dock = DockStyle.Bottom, Text = "Button 1"}),
            (btn2 = new Button { Dock = DockStyle.Bottom, Text = "Button 2"}),
            new TextBox { Dock = DockStyle.Fill, Text = "just text"}
        }
    })
    {
        btn1.Click += delegate {form.Text = "button 1 clicked";};
        btn2.Click += delegate {form.Text = "button 2 clicked";};
        form.KeyPreview = true;
        form.KeyDown += (sender, args) =>
        {
            if (args.KeyCode == Keys.Return) btn1.PerformClick();
        };
        Application.Run(form);
    } 
}
Marc Gravell