Refresh() calls onPaint() immediately during MouseMoving-Event?

  • Thread starter Thread starter c_xyTopa
  • Start date Start date
C

c_xyTopa

hi all,

i have overwritten OnPaint() of a Form. During the MouseMove of the
Panel, wich is contained in that Form, i call Refresh() on the Form.
But it does not seem to call OnPaint() immediately, during the
MouseMove. How can i reach that behavior?

thank you




public class MsgBox : System.Windows.Forms.Form
{
mTitlePanel Panel = new Panel();
this.mTitlePanel.MouseMove += new MouseEventHandler(this.OnMouseMove);


protected void OnMouseMove(object sender, MouseEventArgs e)
{
this.Refresh();
}

protected override void OnPaint(PaintEventArgs e)
{
Pen blackPen = new Pen(Color.Black);
if (this.mMouseDown)
e.Graphics.DrawRectangle( blackPen, this.mRectangle );
else
base.OnPaint (e);
}

}
 
Painting is low priority, so everything else will pre-empt it. Try calling
Application.DoEvents() after Refresh.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
It's not so good idea to draw rectangle in the WM_PAINT event. Much
better solution would be to use double buffering. See this example [1]
which demonstrates how to draw picture using mouse and how to save it as
an monochrome BMP (probably you are trying to achieve the same thing. Am
I right?).

[1] http://www.sergeybogdanov.com/Samples/SaveImage.zip
 
i have a custom message box, wich contains a form and a control/panel.
the panel helps the message box to be movable, because if a Form's
FormBorderStyle is set to None (for resize) it can not be moved.

so now i want to move not the whole message box, but only it's borders
(like the primary message box). after MouseUp the message box should be
rendered where the borders've been moved in order to avoid the
"track"-effect while moving the whole message box.




Sergey said:
It's not so good idea to draw rectangle in the WM_PAINT event. Much
better solution would be to use double buffering. See this example [1]
which demonstrates how to draw picture using mouse and how to save it as
an monochrome BMP (probably you are trying to achieve the same thing. Am
I right?).

[1] http://www.sergeybogdanov.com/Samples/SaveImage.zip

--
Sergey Bogdanov
http://www.sergeybogdanov.com


c_xyTopa said:
hi all,

i have overwritten OnPaint() of a Form. During the MouseMove of the
Panel, wich is contained in that Form, i call Refresh() on the Form.
But it does not seem to call OnPaint() immediately, during the
MouseMove. How can i reach that behavior?

thank you




public class MsgBox : System.Windows.Forms.Form
{
mTitlePanel Panel = new Panel();
this.mTitlePanel.MouseMove += new
MouseEventHandler(this.OnMouseMove);


protected void OnMouseMove(object sender, MouseEventArgs e)
{
this.Refresh();
}

protected override void OnPaint(PaintEventArgs e)
{
Pen blackPen = new Pen(Color.Black);
if (this.mMouseDown)
e.Graphics.DrawRectangle(
blackPen, this.mRectangle );
else
base.OnPaint (e);
}

}
 
Back
Top