leon22
leon22

Reputation: 5649

VS 2008 C# set focus to only one form

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 setting is neccessary in VS2008?

Thanks!

greets leon22

Upvotes: 3

Views: 882

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062865

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.

Upvotes: 5

Related Questions