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

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);
}

}
 
C

Chris Tacke, eMVP

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
 
S

Sergey Bogdanov

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
 
C

c_xyTopa

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);
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top