Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Get Active mdichild form

Get Active mdichild form

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Kode
    wrote on last edited by
    #1

    how to loop through Application openforms and get specified form which is active with note that may be more than one form with the same name is running Form ActvFrm = this.ActiveMdiChild; string cptn = ActvFrm.Name; FrmNewPatiant FNew = (FrmNewPatiant)Application.OpenForms["FrmNewPatiant"]; foreach (Form FrmNew in Application.OpenForms) { if (FrmNew.Text == cptn) { FrmNewPatiant actvNewPat = (FrmNewPatiant)Application.OpenForms[cptn]; actvNewPat.tabNewFile.TabPages[2].Enabled = true; actvNewPat.tabNewFile.SelectedTab = FNew.tabNewFile.TabPages[2]; } }

    A 1 Reply Last reply
    0
    • M Mr Kode

      how to loop through Application openforms and get specified form which is active with note that may be more than one form with the same name is running Form ActvFrm = this.ActiveMdiChild; string cptn = ActvFrm.Name; FrmNewPatiant FNew = (FrmNewPatiant)Application.OpenForms["FrmNewPatiant"]; foreach (Form FrmNew in Application.OpenForms) { if (FrmNew.Text == cptn) { FrmNewPatiant actvNewPat = (FrmNewPatiant)Application.OpenForms[cptn]; actvNewPat.tabNewFile.TabPages[2].Enabled = true; actvNewPat.tabNewFile.SelectedTab = FNew.tabNewFile.TabPages[2]; } }

      A Offline
      A Offline
      Alisaunder
      wrote on last edited by
      #2

      What I used to do was store a value typically the id of the record or individual. I stored this value as the tag value of the child form created. In this way you can make certain not to replicate already created or open form by comparing this value to be created with the values stored in all of the currently open and active forms. I now use Tabs instead of MDI in most of my applications though which is why I said used.

      M 1 Reply Last reply
      0
      • A Alisaunder

        What I used to do was store a value typically the id of the record or individual. I stored this value as the tag value of the child form created. In this way you can make certain not to replicate already created or open form by comparing this value to be created with the values stored in all of the currently open and active forms. I now use Tabs instead of MDI in most of my applications though which is why I said used.

        M Offline
        M Offline
        Mr Kode
        wrote on last edited by
        #3

        can you give me example on how to use tags for each mdi child?

        A 1 Reply Last reply
        0
        • M Mr Kode

          can you give me example on how to use tags for each mdi child?

          A Offline
          A Offline
          Alisaunder
          wrote on last edited by
          #4

          This is how I did it when using MDI. I used a Tree View control populated with A-Z subnodes would be names organized last to first with a comma and middle initial, and I would store the id of the record containing the information in the tag element of the Tree View like so.

          private void updateTreeview()
          {
          //add letters sort nodes
          for (int i = System.Convert.ToInt32('A'); i <= System.Convert.ToInt32('Z'); i++)
          {
          treeView1.Nodes.Add(Convert.ToString((char)(i)), Convert.ToString((char)(i))); //set key and text
          }

                  //add customers
                  TreeNode childnode = null;
                  string sContactsName = null;
                  foreach (DataRow rowContacts in dtContacts.Rows)
                  {
                      sContactsName = string.Concat(rowContacts\["LastName"\].ToString(), ", ", rowContacts\["FirstName"\].ToString());
          
                      if (!(System.Convert.IsDBNull(rowContacts\["MiddleInitial"\].ToString())))
                      {
                          sContactsName = string.Concat(sContactsName, " ", rowContacts\["MiddleInitial"\].ToString(), ".");
                      }
                      //---------------------Key lines here --------------
                      childnode = new TreeNode(sContactsName, 0, 1);
                      childnode.Name = sContactsName; //set text as key
                      childnode.Tag = rowContacts\["ContactID"\].ToString();
                      //--------------------------------------------------
          
                      string sortnode = sContactsName.Substring(0, 1).ToUpper(); //gets alphabet sort node by first letter
                      treeView1.Nodes\[sortnode\].Nodes.Add(childnode);
                  }
          
                  //Update TreeView
                  treeView1.Visible = true;
                  treeView1.Enabled = true;
                  treeView1.ExpandAll();
              }
          

          After the node containing the name was clicked I handled it like this:

              private void treeView1\_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
              {
                  string nodeName = e.Node.Name;
          
                  if (nodeName.Length == 1)
                  {
                      return; //is alphabet sort node, exit
                  }
          
                  //see if child form already exists and show it
                  foreach (Form f in this.MdiChildren)
                  {
                      if (f.Name == nodeName)
                      {
                          f.Activate();
                          return;
                      }
                  }
          
          
                  str
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups