Drawing lines inside a GroupBox

G

Guest

I have a form that I'm drawing some lines on using the DrawLines method. It
all works fine as long as I don't try to draw these lines inside a group box.
When I do, however, the lines don't show. I've tried sending the GroupBox
to the back, but it makes no difference. It seems that I somehow need to be
able to specify that the lines be drawn on the front, or be able to send them
to the front after they are drawn. How can I do this?

Thanks,
Ray
 
G

Guest

Ray Mitchell said:
I have a form that I'm drawing some lines on using the DrawLines method. It
all works fine as long as I don't try to draw these lines inside a group box.
When I do, however, the lines don't show. I've tried sending the GroupBox
to the back, but it makes no difference. It seems that I somehow need to be
able to specify that the lines be drawn on the front, or be able to send them
to the front after they are drawn. How can I do this?

Thanks,
Ray

I set the background color to transparent. Maybe there's a better way? I
think the problem is that my own OnPaint event occurs before the one created
by the IDE, so all of my stuf gets covered up. I'd need to somehow reorder
the events to have my lines come out on top.
 
P

pedrito

The problem is that the group box is a child control of your form, so it's
drawing on top of the form. It always will.

I suppose the transparency is as good a solution as any, if it works. There
are situations where transparency doesn't work and it kind of depends on who
you expect to be using your app. I think there are issues with it, for
example, in Terminal Services.

The alternative is to derive a class from GroupBox and override its OnPaint
method as well.
 
M

Mythran

Ray Mitchell said:
I set the background color to transparent. Maybe there's a better way? I
think the problem is that my own OnPaint event occurs before the one
created
by the IDE, so all of my stuf gets covered up. I'd need to somehow
reorder
the events to have my lines come out on top.

Seems like you are overriding the OnPaint method (not event) for the Form
instead of the control. Instead, try handling the Paint event for the
GroupBox control...

private void groupBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(
Pens.Blue,
0,
(int) (groupBox1.ClientRectangle.Height / 2),
groupBox1.ClientRectangle.Width,
(int) (groupBox1.ClientRectangle.Height / 2)
);
}

The above snip is the handler of a group box control named groupBox1. When
the paint event fires on the groupbox (whenever the control is being
redrawn), the handler paints a blue line half-way down the box.

HTH,
Mythran
 

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