我有一个我想要默认的按钮,但按钮周围没有边框。这可能吗?
感谢。
答案 0 :(得分:1)
如果设置默认按钮,则视觉提示作为标准提示。但是,您可以使用键预览,捕获回车并执行必要的操作来执行某些操作。给出一个C#示例(相同的概念适用于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);
}
}