Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
I want to create controls dynamically in the form
Initially i have textbox1 besides this button1 (text as Plus)
when i click on plus button it has to create textbox2,button2(plus) and also button3(minus) .
e.g: whenever i click on button3(minus) it shouls collapse(remove textbox2,button2,button3) and so on but move all the below controls to top position .............. in this manner i want to add and remove controls .
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);