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. How to use multiple panels in a windows form

How to use multiple panels in a windows form

Scheduled Pinned Locked Moved C#
helptutorialquestion
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.
  • S Offline
    S Offline
    Sonu T
    wrote on last edited by
    #1

    hello everybody!! iam generating a windows form which has a treeview at the left and a splitpanel at its right. the treeview consists of 3 parent nodes with 1 child node in each parent node. the parent nodes have a contextmenu with "Start" and "Stop" as menu items and child nodes have a contextmenu with "Properties" as menuitem. each of the menuitem has an OnClick event handler. what i want is, on clicking the menuitem of each of the child nodes, a different panel should be displayed each time. for this, i need to have 3 panels, one for each childnode. when one panel is being displayed, others should be hidden. my requirement is something similar to the WindowsExplorer, but iam not able to generate the desired o/p. Also, when i right-click on any of the node, the contextmenu is displayed, but after clicking the desired menuitem, the contextmenu just doesnt disappear. am i missing some property tat has to be set for the contextmenu to disappear after selecting a menuitem? this is a part of my code: mnuParentMenu.MenuItems.Add(0, new MenuItem("Start", new System.EventHandler(mnuStart_Click))); mnuParentMenu.MenuItems.Add(1, new MenuItem("Stop", new System.EventHandler(mnuStop_Click))); mnuChildMenu.MenuItems.Add(0, = new MenuItem("Properties", new System.EventHandler(mnuPropertiesC_Click))); TreeNode node = new TreeNode("Parent"); node.Tag = "ParentNodeMenu"; node.ContextMenu = mnuParentMenu; treeView1.Nodes.Add(node); node = new TreeNode("Child"); node.Tag = "ChildNodeMenu"; node.ContextMenu = mnuChildMenu; treeView1.Nodes[0].Nodes.Add(node); I would be thankful to all who wish to take some time and help me out.

    Sonu

    S 1 Reply Last reply
    0
    • S Sonu T

      hello everybody!! iam generating a windows form which has a treeview at the left and a splitpanel at its right. the treeview consists of 3 parent nodes with 1 child node in each parent node. the parent nodes have a contextmenu with "Start" and "Stop" as menu items and child nodes have a contextmenu with "Properties" as menuitem. each of the menuitem has an OnClick event handler. what i want is, on clicking the menuitem of each of the child nodes, a different panel should be displayed each time. for this, i need to have 3 panels, one for each childnode. when one panel is being displayed, others should be hidden. my requirement is something similar to the WindowsExplorer, but iam not able to generate the desired o/p. Also, when i right-click on any of the node, the contextmenu is displayed, but after clicking the desired menuitem, the contextmenu just doesnt disappear. am i missing some property tat has to be set for the contextmenu to disappear after selecting a menuitem? this is a part of my code: mnuParentMenu.MenuItems.Add(0, new MenuItem("Start", new System.EventHandler(mnuStart_Click))); mnuParentMenu.MenuItems.Add(1, new MenuItem("Stop", new System.EventHandler(mnuStop_Click))); mnuChildMenu.MenuItems.Add(0, = new MenuItem("Properties", new System.EventHandler(mnuPropertiesC_Click))); TreeNode node = new TreeNode("Parent"); node.Tag = "ParentNodeMenu"; node.ContextMenu = mnuParentMenu; treeView1.Nodes.Add(node); node = new TreeNode("Child"); node.Tag = "ChildNodeMenu"; node.ContextMenu = mnuChildMenu; treeView1.Nodes[0].Nodes.Add(node); I would be thankful to all who wish to take some time and help me out.

      Sonu

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      Sonu.T wrote:

      what i want is, on clicking the menuitem of each of the child nodes, a different panel should be displayed each time. for this, i need to have 3 panels, one for each childnode. when one panel is being displayed, others should be hidden. my requirement is something similar to the WindowsExplorer, but iam not able to generate the desired o/p.

      How have you implemented it currently and what happens if you click on a child node? Simply setting the Visible property of the panel to be hidden to false and sending it to the back of the ZOrder using SendToBack should work fine, I think. Another approach would be to have a single panel, but different UserControl derived classes. That way, designing the UI would be easier.

      Sonu.T wrote:

      Also, when i right-click on any of the node, the contextmenu is displayed, but after clicking the desired menuitem, the contextmenu just doesnt disappear.

      I'm surprised that you even get the context menu. This[^] KB article shows how to add multiple context menus for different nodes to treeviews. Basically, you subscribe to the MouseUp event, get the point where the mouse was clicked, use the GetNodeAt method to get the TreeNode at that point and then show the appropriate popup menu.

      Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

      S 1 Reply Last reply
      0
      • S S Senthil Kumar

        Sonu.T wrote:

        what i want is, on clicking the menuitem of each of the child nodes, a different panel should be displayed each time. for this, i need to have 3 panels, one for each childnode. when one panel is being displayed, others should be hidden. my requirement is something similar to the WindowsExplorer, but iam not able to generate the desired o/p.

        How have you implemented it currently and what happens if you click on a child node? Simply setting the Visible property of the panel to be hidden to false and sending it to the back of the ZOrder using SendToBack should work fine, I think. Another approach would be to have a single panel, but different UserControl derived classes. That way, designing the UI would be easier.

        Sonu.T wrote:

        Also, when i right-click on any of the node, the contextmenu is displayed, but after clicking the desired menuitem, the contextmenu just doesnt disappear.

        I'm surprised that you even get the context menu. This[^] KB article shows how to add multiple context menus for different nodes to treeviews. Basically, you subscribe to the MouseUp event, get the point where the mouse was clicked, use the GetNodeAt method to get the TreeNode at that point and then show the appropriate popup menu.

        Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

        S Offline
        S Offline
        Sonu T
        wrote on last edited by
        #3

        hello Senthil thanx for replying. i understand that there is no clarity in my query.... iam pasting my entire code here...hope this wud make better sense public partial class Form1 : Form { private System.Windows.Forms.ContextMenu mnuParentMenu = new System.Windows.Forms.ContextMenu(); private System.Windows.Forms.ContextMenu mnuChildMenu = new System.Windows.Forms.ContextMenu(); private MenuItem mnuStart; private MenuItem mnuStop; private MenuItem mnuProperties; private MenuItem mnuPropertiesC; private TreeNode m_OldSelectNode; private TreeNode node; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { mnuParentMenu.MenuItems.Add(0, mnuStart = new MenuItem("Start", new System.EventHandler(mnuStart_Click))); mnuParentMenu.MenuItems.Add(1, mnuStop = new MenuItem("Stop", new System.EventHandler(mnuStop_Click))); mnuParentMenu.MenuItems.Add(2, mnuProperties = new MenuItem("Properties", new System.EventHandler(mnuProperties_Click))); mnuChildMenu.MenuItems.Add(0, mnuPropertiesC = new MenuItem("Properties", new System.EventHandler(mnuPropertiesC_Click))); node = new TreeNode("Credit Files"); node.Tag = "ParentNodeMenu"; node.ContextMenu = mnuParentMenu; treeView1.Nodes.Add(node); node = new TreeNode("VIO Copy Process"); node.Tag = "ChildNodeMenu"; node.ContextMenu = mnuChildMenu; treeView1.Nodes[0].Nodes.Add(node); node = new TreeNode("Human Resources"); node.Tag = "ParentNodeMenu"; node.ContextMenu = mnuParentMenu; treeView1.Nodes.Add(node); node = new TreeNode("Secondary Batch Update Process"); node.Tag = "ChildNodeMenu"; node.ContextMenu = mnuChildMenu; treeView1.Nodes[1].Nodes.Add(node); node = new TreeNode("TimeDeposits"); node.Tag = "ParentNodeMenu"; node.ContextMenu = mnuParentMenu; treeView1.Nodes.Add(node); node = new TreeNode("PurgeProcess"); node.Tag = "ChildNodeMenu"; node.ContextMenu = mnuChildMenu; treeView1.Nodes[2].Nodes.Add(node); node = new TreeNode("SecondaryBatchUpdateProcess"); nod

        S 1 Reply Last reply
        0
        • S Sonu T

          hello Senthil thanx for replying. i understand that there is no clarity in my query.... iam pasting my entire code here...hope this wud make better sense public partial class Form1 : Form { private System.Windows.Forms.ContextMenu mnuParentMenu = new System.Windows.Forms.ContextMenu(); private System.Windows.Forms.ContextMenu mnuChildMenu = new System.Windows.Forms.ContextMenu(); private MenuItem mnuStart; private MenuItem mnuStop; private MenuItem mnuProperties; private MenuItem mnuPropertiesC; private TreeNode m_OldSelectNode; private TreeNode node; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { mnuParentMenu.MenuItems.Add(0, mnuStart = new MenuItem("Start", new System.EventHandler(mnuStart_Click))); mnuParentMenu.MenuItems.Add(1, mnuStop = new MenuItem("Stop", new System.EventHandler(mnuStop_Click))); mnuParentMenu.MenuItems.Add(2, mnuProperties = new MenuItem("Properties", new System.EventHandler(mnuProperties_Click))); mnuChildMenu.MenuItems.Add(0, mnuPropertiesC = new MenuItem("Properties", new System.EventHandler(mnuPropertiesC_Click))); node = new TreeNode("Credit Files"); node.Tag = "ParentNodeMenu"; node.ContextMenu = mnuParentMenu; treeView1.Nodes.Add(node); node = new TreeNode("VIO Copy Process"); node.Tag = "ChildNodeMenu"; node.ContextMenu = mnuChildMenu; treeView1.Nodes[0].Nodes.Add(node); node = new TreeNode("Human Resources"); node.Tag = "ParentNodeMenu"; node.ContextMenu = mnuParentMenu; treeView1.Nodes.Add(node); node = new TreeNode("Secondary Batch Update Process"); node.Tag = "ChildNodeMenu"; node.ContextMenu = mnuChildMenu; treeView1.Nodes[1].Nodes.Add(node); node = new TreeNode("TimeDeposits"); node.Tag = "ParentNodeMenu"; node.ContextMenu = mnuParentMenu; treeView1.Nodes.Add(node); node = new TreeNode("PurgeProcess"); node.Tag = "ChildNodeMenu"; node.ContextMenu = mnuChildMenu; treeView1.Nodes[2].Nodes.Add(node); node = new TreeNode("SecondaryBatchUpdateProcess"); nod

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          Sonu.T wrote:

          about some UserControls in one panel

          You could have separate UserControls instead of separate panels (Right click on Project in Solution Explorer -> Select Add -> UserControl). That way, each of your "panels" will be separate entities at design time. If you put everything in panels directly, then the main form holding all the panels would be congested with controls from different panels (when designing the UI from Visual Studio). So you could have one panel to the right of the splitter and UserControl derived class for each of your screens. You could then load the appropriate control depending on the node selected in the tree. Something like

          TreeNode selectedNode = ...;
          switch(selectedNode.Text)
          {
          case "Weekly Processes";
          panel.Controls.Clear();
          panel.Controls.Add(weeklyProcessesControl);
          break;
          ...
          }

          where panel is the System.Windows.Forms.Panel to the right of the splitter and weeklyProcessesControl is the usercontrol.

          Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro

          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