Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding controls to panel

Status
Not open for further replies.

mjd3000

Programmer
Apr 11, 2009
136
0
0
GB
I am using the following syntax in a loop to add controls to a panel :

this.pnlCharts.Controls.Add(cht);

How can I make it so that there are spaces between each control?
 
Set the control's Location. The default seems to be (0,0)
 
TipGiver's advice is right on the money. When we do this sort of thing, we deal with several attributes of the control after adding it dynamically as you have described. We also dynamically establish events for the control using generic event methods as needed. For example:

Code:
cht.Location = new System.Drawing.Point(x, y);
cht.Name = string.Format("Chart{0}", i.ToString());
cht.Size = new System.Drawing.Size(200, 200);
cht.TabIndex = i;
cht.Visible = true;
cht.Enter += new System.EventHandler(Chart_Enter);

Clearly there are other attributes you can set. The use of "i" assumes that the code either falls inside a for/next loop or other loop where i is incremented on each pass through the loop.

BlackburnKL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top