动态TextBox位置C#

时间:2015-08-10 13:17:27

标签: c# asp.net textbox location

我写了我的第一个应用程序,我遇到了TextBox的问题。我想在单击鼠标的同一位置创建一个文本框。我创建了一个面板并编写了一个方法。

private void allPanel_Click(object sender, EventArgs e)
        {
            MouseEventArgs me = (MouseEventArgs)e;
            Point XY = me.Location;
            TextBox txt1 = new TextBox();
            TextBox txt2 = new TextBox();
            TextBox txt3 = new TextBox();
            TextBox txt4 = new TextBox();
            TextBox txt5 = new TextBox();
            TextBox txt6 = new TextBox();
            Add(ref XY, txt1, txt2, txt3, txt4, txt5, txt6);
        }

private void Add(ref Point loc, TextBox txt1, TextBox txt2, TextBox txt3, TextBox txt4, TextBox txt5, TextBox txt6)
            {
                int locY = 164;
                txt1.Size = new Size(17, 20);
                txt1.Location = new Point(loc.X + 25, locY);
                this.Controls.Add(txt1);
                txt1.BringToFront();
                txt2.Size = new Size(17, 20);
                txt2.Location = new Point(loc.X + 25, locY + 20);
                this.Controls.Add(txt2);
                txt2.BringToFront();
                txt3.Size = new Size(17, 20);
                txt3.Location = new Point(loc.X + 25, locY + 40);
                this.Controls.Add(txt3);
                txt3.BringToFront();
                txt4.Size = new Size(17, 20);
                txt4.Location = new Point(loc.X + 25, locY + 60);
                this.Controls.Add(txt4);
                txt4.BringToFront();
                txt5.Size = new Size(17, 20);
                txt5.Location = new Point(loc.X + 25, locY + 80);
                this.Controls.Add(txt5);
                txt5.BringToFront();
                txt6.Size = new Size(17, 20);
                txt6.Location = new Point(loc.X + 25, locY + 100);
                this.Controls.Add(txt6);
                txt6.BringToFront();
            }

当没有滚动条时,一切正常,但是当我向下滚动时,TextBox在错误的位置创建。像这样:

      GOOD(no scrollbar           |            BAD(scroll down)
     --------[]---------          |           ------------------
     --------[]---------          |           ------------------
     --------[]---------          |           --------[]--------
     --------[]---------          |           --------[]--------
     --------[]---------          |           --------[]--------
     --------[]---------          |           --------[]--------
                                  |                   []
                                  |                   []

有什么问题?

0 个答案:

没有答案