×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Panel won't show up in UserControl

Panel won't show up in UserControl

Panel won't show up in UserControl

(OP)
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?

RE: Panel won't show up in UserControl

gibb99, could explain what you mean by the panel "not showing up"?

I used your classes exactly as specified, and then added QuickStartControl to a form and got this:


Your code seems to work fine, other than the fact that by setting the Anchor of the Panel in the MasterFlowLayoutPanel AFTER the Dock - it clears the Dock property.

RE: Panel won't show up in UserControl

When you add a control programatically, you need to set every property to make sure you create the desired behavior. That includes the Visible property.

So try to set the Visible property on each of the 2 places where you called Control.Add()

wink

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close