Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new form problem c#

Tags:

c#

winforms

I'm aware that this title doesn't say much but it's really hart to explain what I want in few words.

I have two forms (main & help). Once I press button on main form help form pop ups. What I would like to implement is function to block user from doing anything on main form till he close help form.

I would not like to play with visible controls but I would like to have an effect you might have seen on some program that when user tries to click on main form help form "blinks" along with error sound playing. Once user close help form program works as usual

Hope you understand what I meant

like image 343
Anthony Avatar asked Jan 21 '26 19:01

Anthony


2 Answers

This is called a modal dialog, and luckily, the answer is simple; show the child Form with the ShowDialog method instead of using Show. This is a blocking call that will not return until the child form/dialog is closed, so it means that you can check the return value and any properties if needed right after that line of code (probably not useful for a help window, but in most circumstances it is useful to check the user's action).

using( var dlg = new MyHelpDialog() )
{
    if( dlg.ShowDialog() == DialogResult.OK )
    {
        // user chose "OK", do something (?)
        // you can also access properties of the form after the fact
        string whatever = dlg.SomeStringProperty;   
    }
}
like image 189
Ed S. Avatar answered Jan 23 '26 09:01

Ed S.


You're looking for modal forms:

How to: Display Modal and Modeless Windows Forms

like image 26
William Lawn Stewart Avatar answered Jan 23 '26 08:01

William Lawn Stewart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!