DrawReversibleFrame covered by control

P

Paul E Collins

I have a user control consisting of a picture box inside a panel (to
permit scrolling). When the user clicks and drags on the picture box,
I use ControlPaint.DrawReversibleFrame to draw a dashed selection
rectangle.

For some reason, the rectangle does not persist beyond its initial
drawing: I see it very briefly, and then it is "covered up" as though
going behind one of the controls. Why does this happen, and what can I
do about it? (If I use the DrawRectangle method, everything is fine,
but I want the reversible frame for easy "undrawing".)

Here's the Paint event handler for the picture box, if it helps. (The
"_drawing" flag indicates that the user is still holding down the
mouse button.)

private void pic_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Point current = this.PointToClient(Control.MousePosition);

if (_mode == CommandMode.DrawRectangles && _drawing)
{
Rectangle r = Rectangle.FromLTRB(_rectStart.X, _rectStart.Y,
current.X, current.Y);

// Frame will be drawn on the *screen*, not this specific control,
// so offset the rectangle to the control's position.

r.Offset(pic.PointToScreen(new Point(0, 0)));

ControlPaint.DrawReversibleFrame(r, pic.BackColor,
FrameStyle.Dashed);
}
}
 
P

Paul E Collins

Paul E Collins said:
[...] For some reason, the rectangle does not persist beyond
its initial drawing: I see it very briefly, and then it is "covered
up" as though going behind one of the controls. [...]

It seems that drawing the frame in my user control's Paint handler,
rather than its component picture box's Paint handler, has fixed this.

Eq.
 
Top