lis ek

lis ek

  • NA
  • 3
  • 941

Dynamic TextBox location C#

Aug 10 2015 5:26 PM
I'm write my first application and I have problem with TextBox. I want to create a textbox in the same location where I click mouse. I created a panel and wrote a method. 
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();    
   }
All works good when there are no scrollbar, but when I scroll down TextBox are created in wrong location.
http://i.imgur.com/CgnXIJ6.png