Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Forms
Hi,
 
I have 2 forms, form1 activates form2 with showDialog()
Form2 frm2 = new Form2();
            frm2.ShowDialog();
 
but when i click on minimize on the second form, only form2 minimizes but form1 stays at normal state (can be seen).
 
The only thing i thought of is to do this:
private void Form2_SizeChanged(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                foreach (Form frm in Application.OpenForms)
                {
                    frm.WindowState = FormWindowState.Minimized;
                }
            }
            else if(this.WindowState == FormWindowState.Normal)
            {
                foreach (Form frm in Application.OpenForms)
                {
                    frm.WindowState = FormWindowState.Normal;
                }
            }
        }
And when i click on minimize, its good, all forms minimize, but when i click on the taskbar for the application to get back in normal state, only Form1 shows up..
 
So how could i fix this?
Posted 15-Apr-12 4:24am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
What you want to do is not possible when the second form is a modal dialog. See an explanation and a work-around (with code) here[^]
 
Summary:
1) Forcing the main form to minimise actually closes the modal dialog.
2) The work around uses a modeless dialog and simulates modality by temporarily disabling the main form.
 
Alan.
  Permalink  
Comments
VJ Reddy at 15-Apr-12 14:08pm
   
Good answer. 5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
private void Button_open_frm2_Click(object sender, MouseEventArgs e)
        {
            Form2 form2 = new Form2(this);
            form2.ShowDialog();
        }
 
Form2.cs:
 
private Form1 form1 = null;
 
        public Form2(Form invoke_form2)
        {
            form1 = invoke_form2 as Form1;
            InitializeComponent();
 
            if (this.WindowState == FormWindowState.Minimized)
            {
                form1.WindowState = FormWindowState.Minimized;
            }
        }
 

Blind "coded", hope it works for you, give a try if it fits to you.
 
Best Regards
  Permalink  
v2
Comments
Xonfused at 15-Apr-12 10:05am
   
but this doesn't minimize form1 also, it still stays the same...
Björn Ranft at 15-Apr-12 10:27am
   
passing a reference to form1 is needed. Updated my solution. Regards
Xonfused at 15-Apr-12 10:46am
   
this new approach also close Form2 after minimizing, and after restoring the application it brings only form1...
Björn Ranft at 15-Apr-12 10:53am
   
maybe we talk each past other, what do you mean with Form2 is closing after minimizing? I now tried it in my enviroment,form1 and form2 gets minimized, after clicking on one Form (it doesn't matter if I click on Form1 or Form2 in windows taskbar), both Forms are shown (win 7).
Xonfused at 15-Apr-12 11:09am
   
Yes, when minimizing like this it also activates the FormClosing event
But i tested and i saw that if i change from Form2.ShowDialog() to only Form2.Show(), Then it works fine.. but though i would like if it is possible with ShowDialog()
Still, thanks for the answers :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 290
1 Jochen Arndt 165
2 DamithSL 125
3 PIEBALDconsult 110
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 15 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100