开发者

VS 2008 C# set focus to only one form

开发者 https://www.devze.com 2023-04-03 16:54 出处:网络
When my form (AboutForm) is shown I need to hold the focus on this form (the user should only be able to click the OK button) !

When my form (AboutForm) is shown I need to hold the focus on this form (the user should only be able to click the OK button) !

Which sett开发者_高级运维ing is neccessary in VS2008?

Thanks!

greets leon22


You want to show it modally, so use ShowDialog() rather than Show(). That is all.

For example:

using(var frm = new AboutForm()) {
    frm.ShowDialog(this);
}

important: when using ShowDialog, closing the form does not Dispose() it, hence the using; see MSDN:

Unlike modeless forms, the Close method is not called by the .NET Framework when the user clicks the close form button of a dialog box or sets the value of the DialogResult property. Instead the form is hidden and can be shown again without creating a new instance of the dialog box. Because a form displayed as a dialog box is hidden instead of closed, you must call the Dispose method of the form when the form is no longer needed by your application.

0

精彩评论

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