Default Button - Vb.NET
I have a button that I want to开发者_如何学Go make default, but without the border thing around the button. Is this possible to do?
Thanks.
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);
}
}
精彩评论