private int OldValue = 0;
TextBox txt1;
private void Form1_Load(object sender, System.EventArgs e)
{
txt1=new TextBox();
this.Controls.Add(txt1);
txt1.Size = new System.Drawing.Size(42, 23);
txt1.Location = new System.Drawing.Point(4, 128 + 26); } private void hScrollBar1_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
{
if(e.NewValue != OldValue)
{
if(e.NewValue > OldValue)
{   
txt1.Top = txt1.Top + 26;
}
else
{
txt1.Top = txt1.Top + 26;    
}    
OldValue = e.NewValue;
} }这样就OK了。
还有大小写要注意啊。

解决方案 »

  1.   

    能把定义的string变量转换成空间吗?
      

  2.   

    private void Form1_Load(object sender, System.EventArgs e)
    {
                            for(int i=0;i<10;i++)
                            {
    txt1=new TextBox();
    this.Controls.Add(txt1);
                                this.Controls.SetChildIndex(txt1,i); 
    txt1.Size = new System.Drawing.Size(42, 23);
    txt1.Location = new System.Drawing.Point((23*i+4), 128 + 26);
                              } }
    然后用this.Controls[i]來引用就可以了。