开发者

Default Button - Vb.NET

开发者 https://www.devze.com 2022-12-13 18:01 出处:网络
I have a button that I want to开发者_如何学Go make default, but without the border thing around the button. Is this possible to do?

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号