Select Area
-
Hello. I wrote a simple select area, but its working slow when form is maximized, who knows some alternative fast methods for this here is my code sry for bad english
public partial class Form1 : Form
{
bool canResize;
int mX, mY;
Rectangle rect = new Rectangle();public Form1() { InitializeComponent(); } private void Form1\_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawRectangle(new Pen(Brushes.Purple, 2), rect); } private void Form1\_MouseDown(object sender, MouseEventArgs e) { canResize = true; mX = e.X; mY = e.Y; rect.Location = new Point(mX, mY); } private void Form1\_MouseUp(object sender, MouseEventArgs e) { canResize = false; } private void Form1\_MouseMove(object sender, MouseEventArgs e) { if (canResize) { if (mX < e.X) { rect.X = mX; rect.Width = e.X - mX; } else { rect.X = e.X; rect.Width = mX - e.X; } if (mY < e.Y) { rect.Y = mY; rect.Height = e.Y - mY; } else { rect.Y = e.Y; rect.Height = mY - e.Y; } this.Invalidate(); } } }
-
Hello. I wrote a simple select area, but its working slow when form is maximized, who knows some alternative fast methods for this here is my code sry for bad english
public partial class Form1 : Form
{
bool canResize;
int mX, mY;
Rectangle rect = new Rectangle();public Form1() { InitializeComponent(); } private void Form1\_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawRectangle(new Pen(Brushes.Purple, 2), rect); } private void Form1\_MouseDown(object sender, MouseEventArgs e) { canResize = true; mX = e.X; mY = e.Y; rect.Location = new Point(mX, mY); } private void Form1\_MouseUp(object sender, MouseEventArgs e) { canResize = false; } private void Form1\_MouseMove(object sender, MouseEventArgs e) { if (canResize) { if (mX < e.X) { rect.X = mX; rect.Width = e.X - mX; } else { rect.X = e.X; rect.Width = mX - e.X; } if (mY < e.Y) { rect.Y = mY; rect.Height = e.Y - mY; } else { rect.Y = e.Y; rect.Height = mY - e.Y; } this.Invalidate(); } } }
Hi, I suggest you don't create new pens all the time; create one and keep it as a class member instead. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
Hi, I suggest you don't create new pens all the time; create one and keep it as a class member instead. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.