SyntaxHighlighter

2013-10-28

[C#] Custom Dialog Form and Control the DialogResult's value

You can customize any windows form to be a dialog form, with setting the below properties:
Property NameValueNote
FormBorderStyleFixed Dialog
MinimizeBoxFalse
MaximizeBoxFalse
ControlBoxFalse
TopmostTrueOption. To set it if you want the dialog be the most top one even there is other windows programs. Maybe you will like to return it off in most time.
ShowIconFalseWhen use this option, remember to sets ShowInTaskbar to false,too.
As Tod's advice, he leave this true and topmost to false, so the user can switches to another program and get back to this from taskbar.
ShowInTaskbarFalseTo 'hidden' the program from Taskbar.
CancelButtonThe Button object's nameAnd the Button object's property DialogResult will be set to Cancel, too.
StartPositionCenterParent




For set the dialog's DialogResult, you can set it into a button's action or a custom method with
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;

or just set the button's DialogResult property to the value you want to return.

REMEMBER to call the form with ShowDialog() not Show().

0 件のコメント:

人気の投稿