lab12
lab12

Reputation: 6448

Default Button - Vb.NET

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

Thanks.

Upvotes: 0

Views: 1072

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062620

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);
    } 
}

Upvotes: 1

Related Questions