tags:

views:

1619

answers:

1
        private void CreateNewControl()
        {
            List<Control> list = new List<Control>();
            TableLayoutPanel layout = new TableLayoutPanel();
            layout.Dock = DockStyle.Fill;
            this.Controls.Add(layout);
            layout.ColumnCount = 3;
            layout.GrowStyle = TableLayoutPanelGrowStyle.AddRows;

            for (int i = 0; i < 9; i++)
            {

                if (wantedType == DevExpress.XtraEditors.CheckEdit)
                {

                    CheckBox chk = new CheckBox();
                    chk.Tag = i;

                    layout.Controls.Add(chk);
                    layout.AutoScroll = true;

                }


                if (wantedType ==  LabelControl)
                {
                    Label chk = new Label();

                    chk.Tag = i;

                    layout.Controls.Add(chk);
                    layout.AutoScroll = true;

                }

// I want to set the columnwidth of the layout so that when the labels are displayed they do not get clustered and look exactly like when displaying the checkboxes.How do I do it?

+2  A: 

In general, what I do is:

  • Use the IDE in a 'prototype' project, to create a form with the controls in the positions that I want
  • Look at the source code created by the IDE (in the MyFormName.Designer.cs file) to see what source code is generated by the IDE to creat these controls
  • Create my own form in my real project, with hand-coded code that's based on what I learned from the prototype which I created using the IDE
ChrisW