Runtime Control Indexing Problems
am using C#, VS-2005
am generate runtime controls like textBox and works it fine but the Indexing problems on it. my code below as follows.
//tbpoint Declare in GlobalArea.
i开发者_如何学Pythonnt i=0;
TextBox tb= new TextBox();
tb.Location=tbpoint;
tb.Size=new size(970,60);
tb.Name="Tbox"+i.tostring();
tb.Keypress+=new KeypressEventHandler(tbb_Keypress);
tbpoint+=70;
i++;
this.panel1.Controls.Add(tb);
Above Code call in EnterKeypress Event and works fine but the problem is of Indexing the textboxes generated. The index not increment by 1.
How can I Solve It. Please Help Me.
The must declare the variable i also in the class body (which you call "global area"). Otherwise, i is reset on every method call to zero.
If by Index you mean Tab Index, you will need to set that yourself for dynamic controls.
System.Windows.Forms.Control.TabIndex
精彩评论