Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create reference to form

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hello
I have an MDI Form. I have a list of available forms under a window title bar. When the user clicks on the form they want to open, i call the OnClick event for that menu option. I want to be able to then call a routine that will check to see if the form is currently open, if it is then bring it to front, else open it. I pass the name of the form to the routine as a string. If I need to create a reference to the form, how would I do that if all I know is the same of the form? I have searched and searched but nothing came up that meets my needs.

So in short, if I know the name for a form, how can I create a form object to reference that form.

Thanks,
RalphTrent
 
Hi,

When creating the MDI form, you can place an [identifier] in the Tag property of the form. You can then iterate the forms eg.

Code:
foreach (Form mdiChild in this.MdiChildren)
{
  if (mdiChild.Tag.Equals([identifier]))
  {
    this.ActivateMdiChild(mdiChild);
    mdiChild.Activate();    
  }
}

Ryan
 
i found that in order to use the this.MdiChildren collection, the MdiChild must be currently open. I am looking to see how reopen a closed window. Im not sure how your code will work with what I need to do. Can you please explain a little further?

Thanks again,
RalphTrent
 
The code I gave you activates a mdi form that is already open.

To do what you're asking place a flag in the loop eg. FormFound = true. If the form hasn't been found then create a new instance of the mdi form.

If you're still having trouble, post your OnClick event code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top