Well, to start, I would like to say that I read many of things available online to overcome the notorious flickering problem that all programmers face when trying to draw, resize, or even drag somethings on any form.
I started my project trying to dissect the screen into 4 quadrant using the mouse position to draw the dissection lines, however it turned out to be a very challenging job and I can get through with the thing by using a form and draw the dividing lines on that form.
My code snippet is (on the OnPaint event):
[code=c#]
Pen p = new Pen(Color.Red, 5);
Graphics g = this.CreateGrap hics();
g.DrawLine(p, MousePosition.X , 0, MousePosition.X ,
SystemInformati on.PrimaryMonit orSize.Height);
g.DrawLine(p, 0, MousePosition.Y ,
SystemInformati on.PrimaryMonit orSize.Width,
MousePosition.Y );
Refresh();
g.Dispose();
[/code]
Of course the last code will do the job with flickering red lines! so I tried using one of the available double buffering algorithms but it didn't work with me!
The double buffering code snippet is (on the OnPaint event):
[code=c#]
Pen p = new Pen(Color.Red, 5);
Bitmap offScreenBmp;
Graphics offScreenDC;
offScreenBmp = new Bitmap(this.Wid th, this.Height);
offScreenDC = Graphics.FromIm age(offScreenBm p);
Graphics clientDC = this.CreateGrap hics();
offScreenDC.Dra wLine(p, MousePosition.X , 0, MousePosition.X , SystemInformati on.PrimaryMonit orSize.Height);
offScreenDC.Dra wLine(p, 0, MousePosition.Y , SystemInformati on.PrimaryMonit orSize.Width, MousePosition.Y );
clientDC.DrawIm age(offScreenBm p, 0, 0);
Refresh();
[/code]
I really hope that someone will have a solution for this problem.
Note: removing the (Refresh()) will not update the drawing!
I started my project trying to dissect the screen into 4 quadrant using the mouse position to draw the dissection lines, however it turned out to be a very challenging job and I can get through with the thing by using a form and draw the dividing lines on that form.
My code snippet is (on the OnPaint event):
[code=c#]
Pen p = new Pen(Color.Red, 5);
Graphics g = this.CreateGrap hics();
g.DrawLine(p, MousePosition.X , 0, MousePosition.X ,
SystemInformati on.PrimaryMonit orSize.Height);
g.DrawLine(p, 0, MousePosition.Y ,
SystemInformati on.PrimaryMonit orSize.Width,
MousePosition.Y );
Refresh();
g.Dispose();
[/code]
Of course the last code will do the job with flickering red lines! so I tried using one of the available double buffering algorithms but it didn't work with me!
The double buffering code snippet is (on the OnPaint event):
[code=c#]
Pen p = new Pen(Color.Red, 5);
Bitmap offScreenBmp;
Graphics offScreenDC;
offScreenBmp = new Bitmap(this.Wid th, this.Height);
offScreenDC = Graphics.FromIm age(offScreenBm p);
Graphics clientDC = this.CreateGrap hics();
offScreenDC.Dra wLine(p, MousePosition.X , 0, MousePosition.X , SystemInformati on.PrimaryMonit orSize.Height);
offScreenDC.Dra wLine(p, 0, MousePosition.Y , SystemInformati on.PrimaryMonit orSize.Width, MousePosition.Y );
clientDC.DrawIm age(offScreenBm p, 0, 0);
Refresh();
[/code]
I really hope that someone will have a solution for this problem.
Note: removing the (Refresh()) will not update the drawing!
Comment