You can move controls around on the form dynamically by setting their Control.Left and their Control.Top properties. As for creating new ones, it's also pretty simple, just create them in code, add them to the parent form then set their top and left Properties
TextBox t = new TextBox();
t.Top = 10;
t.Left = 10;
1. Create a user control that has Button and TextBox in it.
2. Add a FlowLayoutPanel to your form and set its FlowDirection as TopDown.
3. Handle the button click event of the button in the Form itself (through delegate). And then add and remove controls at your will. They will move up/down automatically.
This is happening beause the method is being called 100s of times when moving the mouse in one "jesture" over a significant distance. Put a breakpoint on and you'll see what I mean, the method is called almost per pixel moved.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
I've tried it but the form is still freezing and I've no control over it.
Here is the code I have in my OnPaint method.
protectedoverridevoid OnPaint(PaintEventArgs e)
if (session == 0)
Graphics dc = e.Graphics;
Pen CyanPen = new Pen(Color.Cyan, 1);
Pen MagentaPen = new Pen(Color.Magenta, 1);
Pen YellowPen = new Pen(Color.Yellow, 1);
Pen BlackPen = new Pen(Color.Black, 1);
Random rnd = new Random();
int buff = 0;
for (int y = 0; y < 300; y++)
for (int x = 0; x < 300; x++)
buff = rnd.Next(0, 4);
if (buff == 0)
dc.DrawRectangle(CyanPen, x, y, 1, 1);
if (buff == 1)
dc.DrawRectangle(MagentaPen, x, y, 1, 1);
if (buff == 2)
dc.DrawRectangle(YellowPen, x, y, 1, 1);
if (buff == 3)
dc.DrawRectangle(BlackPen, x, y, 1, 1);
I see. But there is some thing that I don't understand. If I use OnPaint method, only for the painting process while randomizing in another method; how am I going to transfer my variables like color and position to the OnPaint method? I can use global variables but is it a good solution? There should be an easier and neater solution.
Last Visit: 31-Dec-99 18:00 Last Update: 2-Oct-23 1:34