Only one form running in runtime.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • qiux
    New Member
    • Jan 2008
    • 1

    Only one form running in runtime.

    hi i am a newbie here.
    kindly need your help for VB NET issue.
    my problem is i want only one form run in runtime.
    case: i have a mdiform which got a lot menu, eg. File - Open - Employee and File - Open - Product
    when i click Employee, employee form show then if i click Product, employee form directly have to been closed.
    so only left Product form in runtime and reversely.
    i met a problem at here,
    anyone can help me, please..
    thanks in adcance and last.
  • camel
    New Member
    • Jan 2008
    • 55

    #2
    There is not a single answer to this, you basically have to keep track of last active form, load new form, and dispose the previous. The following uses a public property on the parent MDI form that sets a local variable to hold the previous form handle just before setting new child form value, then LoadForm().
    It was readily to hand but should give you a good idea of how to approach it.

    Code:
            private void LoadForm()
            {
                if(mobjPreviousChildForm!=null)
                {
                    mobjPreviousChildForm.Hide();
                }
    
    			if( this.ChildForm != null && !( this.ChildForm.Disposing ) )
    			{
    				if( this.ChildForm is frmSearch && mobjLastSearchForm != null )
    				{
    					this.ChildForm = mobjLastSearchForm;
    				}
    				ChildForm.MdiParent = this;
    				ChildForm.Top = 0;
    				ChildForm.Left = 0;
    				ChildForm.WindowState = FormWindowState.Maximized;
    
                    Shared.WriteToEventlog("Starting ChildForm.Show routine for " + ChildForm.Name);
                    ChildForm.Show();
                    Shared.WriteToEventlog("Ending ChildForm.Show routine for " + ChildForm.Name);
    			}
    
    			if (mobjPreviousChildForm != null)
                {
    				if (!mobjPreviousChildForm.GetType().Equals(typeof(frmSearch)))
    				{
    					mobjPreviousChildForm.Close();
    					mobjPreviousChildForm.Dispose();
    					mobjPreviousChildForm = null;
    				}
    				else
    				{
    					mobjLastSearchForm = (frmSearch)mobjPreviousChildForm;
    				}
                }
            }

    Comment

    Working...