Hey,
I have 2 groupboxes which I would like to customise a bit more, and I dont want to resort to having a panel with a label (this would mean that I would have to have the same background colour for the panel and the parent control if I wanted a border, since the label would have to have a colour set to cover up the border behind the text).
I have managed to change the border colour by capturing the paint event and using the following code:
Graphics gfx = e.Graphics;
Pen p = new Pen(Color.FromArgb(86, 136, 186), 3);
GroupBox gb = (GroupBox)sender;
Rectangle r = new Rectangle(0, 0, gb.Width, gb.Height);
gfx.DrawLine(p, 0, 5, 0, r.Height - 2);
gfx.DrawLine(p, 0, 5, 10, 5);
gfx.DrawLine(p, 62, 5, r.Width - 2, 5);
gfx.DrawLine(p, r.Width - 2, 5, r.Width - 2, r.Height - 2);
gfx.DrawLine(p, r.Width - 2, r.Height - 2, 0, r.Height - 2);
My problem is that, like this, if the caption is too long then it overlaps the border. As it is it overlaps the left hand border at the top - thats easy to solve simply by adjusting the 2nd DrawLine
line. However I would like to detect the x and width measurements of the text so that I can position the borders properly.
Does anyone have any idea how to do this? I have looked on Google for a while but nothing jumps out at me. I know the caption is set through GroupBox.Text
.
Please also say if there are any other measurements I may need, on the basis that I am changing the border thickness too so it would look odd if the font was tiny but the border was 10 pixels starting half way down...
Thanks in advance.
Regards,
Richard