none
How to disable child form1 when any child form2 is open. RRS feed

  • Question

  • HI,

    I have a MDI form, from there i open a child form1. Child form1 has textbox, dropdown,etc. When i double click textbox, another child form2 opens.
    Now my requirement is child form1 should be disabled or should not get focus unless child form1 is closed. How do i do this?

    Thanks
    Monday, December 28, 2009 6:55 AM

Answers

  • Hi

    You can disable form1 just before opening the form2 and enable form1 again on the closed event of form2

    Here is a sample.

    //form1
        public partial class frmSub1 : Form
        {
            public frmSub1()
            {
                InitializeComponent();
    
            }
    
    
    
            private void textBox1_DoubleClick(object sender, EventArgs e)
            {
                frmSub2 f = new frmSub2();
                f.MdiParent = this.MdiParent;
                f.OpenerForm = this;
                f.Show();
                this.Enabled = false;
            }
    
    
        }
    //form2
        public partial class frmSub2 : Form
        {
            public frmSub2()
            {
                InitializeComponent();
    
    
    
    
            }
            public Form OpenerForm { get; set; }
            private void frmSub2_Load(object sender, EventArgs e)
            {
            
            }
    
            private void frmSub2_FormClosed(object sender, FormClosedEventArgs e)
            {
                OpenerForm.Enabled = true;
            }
    
    
    
       
        }
    • Marked as answer by SamipKS Monday, December 28, 2009 11:07 AM
    Monday, December 28, 2009 7:28 AM

All replies

  • Hi

    You can disable form1 just before opening the form2 and enable form1 again on the closed event of form2

    Here is a sample.

    //form1
        public partial class frmSub1 : Form
        {
            public frmSub1()
            {
                InitializeComponent();
    
            }
    
    
    
            private void textBox1_DoubleClick(object sender, EventArgs e)
            {
                frmSub2 f = new frmSub2();
                f.MdiParent = this.MdiParent;
                f.OpenerForm = this;
                f.Show();
                this.Enabled = false;
            }
    
    
        }
    //form2
        public partial class frmSub2 : Form
        {
            public frmSub2()
            {
                InitializeComponent();
    
    
    
    
            }
            public Form OpenerForm { get; set; }
            private void frmSub2_Load(object sender, EventArgs e)
            {
            
            }
    
            private void frmSub2_FormClosed(object sender, FormClosedEventArgs e)
            {
                OpenerForm.Enabled = true;
            }
    
    
    
       
        }
    • Marked as answer by SamipKS Monday, December 28, 2009 11:07 AM
    Monday, December 28, 2009 7:28 AM
  • Tamer Oz Solution is Correct . Additionally you need to check form1 instance  is already opened or not while clicking form1 menu at next time

    You can check the instance already opened or not , By Using Form Name or Form Tag
     



    Happy Coding, RDRaja
    Monday, December 28, 2009 9:54 AM
  • Please Mark the Answers for your Question  except your reply



    Happy Coding, RDRaja
    Monday, December 28, 2009 11:03 AM