通过设置窗体的AcceptButton属性,可以设置窗体的“接受”按钮,若此设计,则用户每次按下Enter键都相当于单击该按钮

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Text;
 7 using System.Windows.Forms;
 8 
 9 namespace Test02
10 {
11     public partial class Form1 : Form
12     {
13         public Form1()
14         {
15             InitializeComponent();
16         }
17 
18         private void Form1_Load(object sender, EventArgs e)
19         {
20             this.AcceptButton = button1;
21         }
22 
23         private void button1_Click(object sender, EventArgs e)
24         {
25             MessageBox.Show("引发了接受按钮");
26         }
27     }
28 }

 

posted @ 2015-11-11 11:49  刘要直  阅读(1924)  评论(0编辑  收藏  举报