Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application i have a mainform which is the MDIPARENT of all other forms of my application on login by default this form is opened and from menustrip in this form we are navigating to other forms
itsis like


C#
public partial class MainMenuForm : Form
        {
            public MainMenuForm()
            {
               
                InitializeComponent();
                this.WindowState = FormWindowState.Maximized;
            }
      private void humanResourceToolStripMenuItem_Click(object sender, EventArgs e)
            {
                HumanResourceForm humanresourceform = new HumanResourceForm();
                humanresourceform.MdiParent = this;
                humanresourceform.Show();
    
            }
    
    }


inside the humanresourceform i had a button which will navigate to anotherform say employetransferform



C#
private void button1_Click(object sender, EventArgs e)
           {
               Administraror.Humanresource.EmployetransferForm emptranfrm = new    Administraror.Humanresource.EmployetransferForm();

               emptranfrm.ShowDialog();

           }


Now my problem is Inside the emplyeetransferform I want to get some values from the controls of Humanresources
also the user should not be allowed to close the humanresourceform when the employee trnsfer form is open or active

I also want to get the textproperty of a textbox of humanresource in emplyeetransferform like
C#
public partial class EmpLoctnChangeForm : Form 
    {
        public EmpLoctnChangeForm( )
        {
            InitializeComponent();
           
        }

        private void EmpLoctnChangeForm_Load(object sender, EventArgs e)
        {
          intemppk= humanresourceform.txtpk.text;
        }
    }



expecting some nice advice from all Thanks in advance
Posted

I would suggest some redesign of the user interface and code.

  • Don't communicate between the forms directly. Instead use a separate classes for the data and the logic. If needed, these classes may interact.
  • If a form cannot be closed while another form is open, typically the form preventing the close should be a modal dialog, not an MDI child
  • If you don't want to use a modal dialog, then I would suggest placing the data on single form, possibly on separate tabs.
 
Share this answer
 
Comments
Manas Bhardwaj 20-May-12 14:24pm    
nice +5!
Wendelius 20-May-12 14:31pm    
Thanks :)
SREENATH GANGA 20-May-12 14:58pm    
thank you
Wendelius 20-May-12 15:00pm    
You're welcome :)
Clifford Nelson 20-May-12 23:14pm    
You are wrong on several accounts.

First of all you don't even want to have the data in the form class, you want to use MVP/MVC. However that is much more complex than just using another class. I do not see much point in using another class for just this communication.

There are good reasons for there to be a child form that does not prevent access to the parent form. The Microsoft Office Find Replace dialog is a good example. Users get use to being able to go between the two. I could give you tons of examples where you might want to do this.

I have never been a fan for MDI form, and seems that it is one its way to oblivian, thank god
You can always create a public property on form you want access to the values, and just access the control's value. Not generally considered good practice, but a good quick and dirty. Would be better to use an MVC/MVP pattern where the data is in a separate class from the view.

Also, you can use a bool public property on the form to indicate that form cannot be closed. On the close event check if this flag is set, and cancel the close. I would not say that depending on dialog is necessarily good practice since may want to interact with both forms, the second form being a detailed information form or something else. A case where Microsoft has changed their position is the find replace dialog in Office. Now you can go between the find replace form and the main form.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900