Why are the controlpaint draw methods paint outside of its client paint area?

380 Views Asked by At

I have a winform on which I want to draw dashed frame as you click the left mouse button and drag. When the left mouse button is released, the frame should disappear. I am able to do that with ControlPaint.DrawReversibleFrame method. However, it draws outside of the winform every time not within the winform. It seems controlpaint methods using the screen as the paint area not the winform. Am I correct?

If my assumption is correct, how do you tell controlpaint to use winform as its paint area.

Thanks,

1

There are 1 best solutions below

3
On BEST ANSWER

ControlPaint does "cheat" by drawing on the desktop.

A work around to try is to watch the dimensions yourself. Once you get to the border of your control, stop calling it.

Updated:

It sounds like you aren't necessarily converting your dimensions correctly.

Here is a simple example to always draw on a panel1 control:

private void panel1_Paint(object sender, PaintEventArgs e) { 
  ControlPaint.DrawReversibleFrame(
    new Rectangle(panel1.PointToScreen(new Point(32, 32)), new Size(64, 64)), 
    panel1.BackColor, 
    FrameStyle.Dashed);
}