Powered by Blogger.

Sunday, March 2, 2014

Open windows form as modal dialog box in C#.Net



In this post we will discuss how we can open a windows form as a dialog box in C#.Net. Also you can check my previous posts on:

- Drop Primary Key Constraint in sql server 2008

- Rename table name or column name in sql server 2008

- Rename database in sql server 2008

We can open a windows form as a dialog box by using the ShowDialog method of the windows form. Below is the code:

MaximizeTest objMaximizeTest = new MaximizeTest();

objMaximizeTest.ShowDialog();

Here MaximizeTest is the windows form name and we are calling the ShowDialog() Method of the class.

But if you want to return the DialogResult then you can write like below:

MaximizeTest objMaximizeTest = new MaximizeTest();

DialogResult result = objMaximizeTest.ShowDialog();

DialogResult is an enum which can contain value like: Abort, Cancel, Ignore, No, None, OK, Retry, Yes.

According to these result you can perform some action.



0 comments

Post a Comment