CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011
    Posts
    63

    Panel won't show up in UserControl

    Hello,

    I want to add a Panel to a UserControl but it's not showing up.

    Here's my code:

    Adding the UserControl (to another UserControl -- i.e. QuickStartControl):

    Code:
        public partial class QuickStartControl : UserControl
        {
            public QuickStartControl()
            {
                InitializeComponent();
                this.Load += new EventHandler(QuickStartControl_Load);
            }
    
            private void QuickStartControl_Load(object sender, EventArgs e)
            {
                MasterFlowLayoutPanel masterFlow = new MasterFlowLayoutPanel();
                masterFlow.Dock = DockStyle.Top;
                masterFlow.BackColor = Color.Black;
                this.Controls.Add(masterFlow);
            }
        }
    Adding the panel to the MasterFlowLayoutPanel UserControl:

    Code:
        public partial class MasterFlowLayoutPanel : UserControl
        {
            public MasterFlowLayoutPanel()
            {
                InitializeComponent();
                this.Load += new EventHandler(MasterFlowLayoutPanel_Load);
            }
    
            private void MasterFlowLayoutPanel_Load(object sender, EventArgs e)
            {
                AddInitialSafeguardFlowLayoutPanel();
            }
    
            public void AddInitialSafeguardFlowLayoutPanel()
            {
                Panel p = new Panel();
                p.Location = new Point(0, 0);
                p.Size = new Size(100, 100);
                p.Dock = DockStyle.Fill;
                p.Anchor = AnchorStyles.Left | AnchorStyles.Right;
                p.BackColor = Color.Red;
                this.Controls.Add(p);
    	}
        }
    The panel won't show up. Any idea why?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Panel won't show up in UserControl

    Do you have to add the control in the OnLoad? Could you add it from the form designer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured