locked
Parent Form Minimizes when the Child Form Closes in Winforms C# RRS feed

  • Question

  • Hi,

    I have a winforms application where I'm using lots of Forms. Now I'm calling few forms from the MainForm inside my code.

    Now Lets assume my MainForm is A and the Child form is B.

    I have to add certain values(folder paths) to the ListView of A by using form B. ie There will be a button named "ADD" in the form A and when i click that form B will be opened.

    Form A

    Form B is opened as a dialog

    private void BtnAdd_Click(object sender, EventArgs e)
            {
                FormB b = new FormB();
                b.ShowDialog(this);
            }


    Form B is as follows

    Form B

    Now i can add any value using form B. There is a FolderBrowserDialog that helps get the folder path.

    The following is the Click even of Apply button

    private void btnExcludeFolderApply_Click(object sender, EventArgs e)
    {
    	//Set of Code
    
    	this.Close();
    }

    and the click event of Cancel button

    private void btnExcludeFolderCancel_Click(object sender, EventArgs e)
            {
                DialogResult = DialogResult.Cancel;
            }

    Now my main issue is after clicking the Apply Button or Cancel Button the form B closes, but at the same time my Main form A minimizes. I dont know how that happens. Is there anything i need to do in order to control this. Basically what i want is that when the form B is closed my Main Form A should not be minimized.

    Thanks in Advance

    Friday, May 2, 2014 11:42 AM

Answers

  • Thanks for the Reply Barry Wang, As you suggested, I created a new project and tried the same. But this being a typical issue I wasnt able to reproduce it.

    So I did spent sometime doing and trying different things. In my application I was facing this issue at almost 8 places. I did some changes and eventually ended up eliminating the issue.

    In all the places I was using

    private void BtnAdd_Click(object sender, EventArgs e)
    {
    	FormB b = new FormB();
    	b.ShowDialog(this);
    }

    So I decided to change ShowDialog() into Show() and replaced almost at all the places.

    In a particular button click event I changed the code to 

    private void btnAdd_Click(object sender, EventArgs e)
    {
    	var nrv = new FormB();
    
    	if (nrv.ShowDialog(this) == DialogResult.OK)
    	{
    		//Some process
    
    	}
    	this.WindowState = FormWindowState.Normal;
    	
    	/*
    	Function to refresh the ListView. Couldnt use nrv.Show()
    	*/
    }

    In the above code I just added

    this.WindowState = FormWindowState.Normal;
    and so far the Application is working fine for me ie it doesnt get minimized whenever there is Child form closes.
    • Marked as answer by Barry Wang Thursday, May 15, 2014 9:38 AM
    Wednesday, May 7, 2014 3:33 PM

All replies

  • Hi Vikneshwar,

    The same simple case hasn't reproduced your issue, I use code from apply button and my main form is not minimized. 

    Do you have any other code which may affects this isuse and can you also test on a simple project instead of current project?

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 5, 2014 8:23 AM
  • Thanks for the Reply Barry Wang, As you suggested, I created a new project and tried the same. But this being a typical issue I wasnt able to reproduce it.

    So I did spent sometime doing and trying different things. In my application I was facing this issue at almost 8 places. I did some changes and eventually ended up eliminating the issue.

    In all the places I was using

    private void BtnAdd_Click(object sender, EventArgs e)
    {
    	FormB b = new FormB();
    	b.ShowDialog(this);
    }

    So I decided to change ShowDialog() into Show() and replaced almost at all the places.

    In a particular button click event I changed the code to 

    private void btnAdd_Click(object sender, EventArgs e)
    {
    	var nrv = new FormB();
    
    	if (nrv.ShowDialog(this) == DialogResult.OK)
    	{
    		//Some process
    
    	}
    	this.WindowState = FormWindowState.Normal;
    	
    	/*
    	Function to refresh the ListView. Couldnt use nrv.Show()
    	*/
    }

    In the above code I just added

    this.WindowState = FormWindowState.Normal;
    and so far the Application is working fine for me ie it doesnt get minimized whenever there is Child form closes.
    • Marked as answer by Barry Wang Thursday, May 15, 2014 9:38 AM
    Wednesday, May 7, 2014 3:33 PM