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