导航

c# WinForm加载焦点

Posted on 2014-12-01 15:11  eastson  阅读(293)  评论(0编辑  收藏  举报

1.c# WinForm在加载时把焦点设在按钮上

this.AcceptButton = button1;

这样在WinForm窗口中,

按钮的状态会变成窗口的默认按钮,

只要按下Enter键,就会触发按钮的单击事件

这种效果与按钮获得焦点类似.

 当然,加个button1.Focus();更好。

2.c# WinForm在加载时把焦点设在textBox上

两种方法:

1 在Load中设置 
this.ActiveControl = this.textBox;

2 this.textBox.Focus(); 
但在Form_Load设置会无效,可在Form_Paint()中设置.