none
Visual C# 2010 - Hide Panel in Design View Mode

    Question

  • Hello,

    I've a split container where I want to have the left side panel contain many panels that change as I toggle through a menu list. While designing these panels, if I set them all to have the same parent container, eventually only one panel will display as the most forefront panel, and I am unable to see my other panels to edit them. How can I hide panels so I can edit my other panels in design mode? 

    My next question is similiar. When I add a new panel to the left side of the split container I have to go into the code view in order to change the parent panel of the new panel to the left side of the split container or else it will be embedded within a child panel of that same left side of the split container. Where can I go within the properties box to define which panel is the parent panel of the object?

    Thank you for any help!

    HudsonSubmit


    Sunday, October 09, 2011 9:02 PM

Answers

  • Hi Hudson,

    Welcome to the MSDN Forum.

    For the first question, if you want to set the parent control to the panel, you can use panelName.Parent=parentControl.

    Or if you want to add it to the Design property grid in the Visual Studio, you can create a UserControl, such as:

    public partial class MyPanel : Panel
    {
        public MyPanel()
        {
            InitializeComponent();
        }
    
        [DisplayName("ParentControl")]
        public Control ParentControl
        {
            get
            {
                return Properties.Settings.Default.ParentControl;
            }
            set 
            {
                this.Parent = value;
                Properties.Settings.Default.ParentControl = value;
            }
        }
    }
    

    It will add a custom property to let you set it in the Design Property Grid:

    In order to test it, you can create a Windows Form and test is like[Suppose you've add 3 MyPanles and show it one by one at the top of the Form]:

    private int ncount = 0;
    
    private void button1_Click(object sender, EventArgs e)
    {
        ncount++;
    
        switch (ncount % 3)
        {
            case 0:
                this.myPanel1.ParentControl = this;
                this.myPanel1.Dock = DockStyle.Fill;
                this.myPanel1.BringToFront();
    
                break;
            case 1:
                this.myPanel2.ParentControl = this;
                this.myPanel2.Dock = DockStyle.Fill;
                this.myPanel2.BringToFront();
                break;
            case 2:
                this.myPanel3.ParentControl = this;
                this.myPanel3.Dock = DockStyle.Fill;
                this.myPanel3.BringToFront();
                break;
            default:
                ncount = 0;
                break;
        }
    
        (sender as Button).BringToFront();
    }
    

    It will works fine.


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Monday, October 17, 2011 6:23 AM
    Tuesday, October 11, 2011 6:31 AM
  • For the second question, I think you know know about the Dock property and the Anchor property.

    When you drag the Panel to the Form, you should know which the parent control is. So, at the Draging/Droping time, you should drag/drop the panel into the container control so that the Visual Studio will help you to add the panel to the container control and by default, the container control should be the parent control.

    Suppose you drag/drop a panle named panle2 into the panel1, the panel1 will be the parent control to the Panel2. It is by default except you change it.

    And by using the splite control, you will need to set the panels can be extended automatically. So, the DockStyle/Anchor is necessarily.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Monday, October 17, 2011 6:23 AM
    Tuesday, October 11, 2011 6:39 AM

All replies

  • Hi Hudson,

    Welcome to the MSDN Forum.

    For the first question, if you want to set the parent control to the panel, you can use panelName.Parent=parentControl.

    Or if you want to add it to the Design property grid in the Visual Studio, you can create a UserControl, such as:

    public partial class MyPanel : Panel
    {
        public MyPanel()
        {
            InitializeComponent();
        }
    
        [DisplayName("ParentControl")]
        public Control ParentControl
        {
            get
            {
                return Properties.Settings.Default.ParentControl;
            }
            set 
            {
                this.Parent = value;
                Properties.Settings.Default.ParentControl = value;
            }
        }
    }
    

    It will add a custom property to let you set it in the Design Property Grid:

    In order to test it, you can create a Windows Form and test is like[Suppose you've add 3 MyPanles and show it one by one at the top of the Form]:

    private int ncount = 0;
    
    private void button1_Click(object sender, EventArgs e)
    {
        ncount++;
    
        switch (ncount % 3)
        {
            case 0:
                this.myPanel1.ParentControl = this;
                this.myPanel1.Dock = DockStyle.Fill;
                this.myPanel1.BringToFront();
    
                break;
            case 1:
                this.myPanel2.ParentControl = this;
                this.myPanel2.Dock = DockStyle.Fill;
                this.myPanel2.BringToFront();
                break;
            case 2:
                this.myPanel3.ParentControl = this;
                this.myPanel3.Dock = DockStyle.Fill;
                this.myPanel3.BringToFront();
                break;
            default:
                ncount = 0;
                break;
        }
    
        (sender as Button).BringToFront();
    }
    

    It will works fine.


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Monday, October 17, 2011 6:23 AM
    Tuesday, October 11, 2011 6:31 AM
  • For the second question, I think you know know about the Dock property and the Anchor property.

    When you drag the Panel to the Form, you should know which the parent control is. So, at the Draging/Droping time, you should drag/drop the panel into the container control so that the Visual Studio will help you to add the panel to the container control and by default, the container control should be the parent control.

    Suppose you drag/drop a panle named panle2 into the panel1, the panel1 will be the parent control to the Panel2. It is by default except you change it.

    And by using the splite control, you will need to set the panels can be extended automatically. So, the DockStyle/Anchor is necessarily.

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Neddy Ren Monday, October 17, 2011 6:23 AM
    Tuesday, October 11, 2011 6:39 AM