locked
FlowLayoutPanel problem - User control does not appear RRS feed

  • Question

  • Hi all!

    I am in trouble trying to add some controls at a FlowLayoutPanel.

    In my app, there is a tabcontrol and a class named TabPageEx which extends TabPage.

    TabPageEx contains a FlowLayoutPanel and here I will show you the constructor of this class:

            public TabPageEx(System.Windows.Forms.TabControl tcDataPanes) : base () {

                tcDataPanes.TabPages.Add("New tab");

                //Setting the main interface to go to the new tab
                tcDataPanes.SelectTab(tcDataPanes.TabPages.Count - 1);
                this.flowLayoutPanel1 = new FlowLayoutPanel();
                this.Controls.Add(flowLayoutPanel1);

                this.flowLayoutPanel1.Dock = DockStyle.Fill;
                this.flowLayoutPanel1.Name = "PanelOfControls";
            }

    The problem is when I try to add a user control, such as a button at the FlowLayoutPanel which is in the tabPageEx object. In order to do it, the app execute the following function:


            private void button1_Click(object sender, EventArgs e) {
                int x;
                if (tcDataPanes.TabCount == 0) {
                    this.tabPageEx = new TabPageEx(tcDataPanes);
                    this.tabPageEx.getFlowLayoutPanel().Controls.Add(new Button());
                    this.tabPageEx.getFlowLayoutPanel().Controls.Add(new Button());
                    x = this.tabPageEx.getFlowLayoutPanel().Controls.Count;

                    return;
                }
                ...
            }


    As you can see, I check if the controls are created or not. The x value after I execute this function is 2, so, the objects are created but they are not shown.

    However, nothing occurs, in other words, nothing appears at the screen.

    If I try to add some objects using this piece of code:

      tcDataPanes.SelectedTab.Controls.Add(dial);


    The object appears. But it is not what I want to do. I need to add the objects at flowLayoutPanel1 because I need to use its properties. How can I add the objects at flowLayoutPanel1 correctly at run time? How can I show to the user these objects which are dynamically created?

    Thank you in advance.
    • Moved by jack 321 Friday, June 20, 2008 9:43 AM off topic
    Tuesday, June 17, 2008 5:24 PM

Answers

All replies