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.
use class members to do so, and make sure your Paint handler executes fast.
I suggest you read this[^] little article of mine.
Luc Pattyn [Forum Guidelines][Why QA sucks][My Articles] I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
modified on Friday, February 26, 2010 12:58 PM
Last Visit: 31-Dec-99 18:00 Last Update: 2-Oct-23 14:57