Creating C# winform simple dynamic controls

 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?

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

http://stackoverflow.com/questions/125109/winforms-datagridview-binding-to-a-listt

About eagle081183

Passionate, Loyal
This entry was posted in ASP.NET MVC, C#. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s