views:

128

answers:

3

A lable sized like a rectangle with no text but has a border and is invisible (for a visual rectangle on the form around controls but not to contain the controls) or a panel?

+3  A: 

What you want to use is a GroupBox. Not that it really matters, most likely, but a label should be cheaper than a panel.

jeffamaphone
In this case, it is a form with a tab control that has 32 pages. yes it is huge, but it is a form that is rarely used and it must contain all 32 pages. The rectangle is only for visible separation of controls on the pages. I have panels right now and of course, with 32 pages it is slow loading. I am going to try replacing the panels with labels and see if it is better. No, the design is not going to change no matter whether the entire world thinks it should be broken up into multiple forms :o) Thank you!
TCH
That is an awful design. Honestly, no tab control should ever have 32 pages, it is simply not usable.
Ed Swangren
That does not answer the question. Sometimes design decisions are not made by the developer and you have to live with it.
TCH
+1  A: 

The answer is; it doesn't matter which has the smaller footprint, and if it does you have a design problem (i.e., you have way too many controls on your form). Anyhow, you should just use the control that fits the job, in this case, a Panel or a GroupBox.

Ed Swangren
A: 

If this is really a problem, then the best way to provide a visual separation between controls is to handle each tab page's Paint event, and use e.Graphics.FillRectangle(...) to draw the separator. You would get rid of a very large number of controls that way.

If you can't do something as simple as just drawing a rectangle underneath each control on each tab page, you can write a code-generating routine that you run one time on the form, and for each tab page you generate something like this (by iterating through all the separator controls on the page):

List<Rectangle> rects = new List<Rectangle>();
rects.Add(new Rectangle(10, 40, 200, 5)); // position of first separator
rects.Add(new Rectangle(10, 80, 200, 5)); // position of second separator
// etc.

Then you copy-and-paste these generated code routines into your application, and use them for each page's Paint event, like so:

SolidBrush brush = new SolidBrush(Color.PeachPuff);
foreach (Rectangle rect in rects)
{
    e.Graphics.FillRectangle(brush, rect);
}

Then you delete all the separators from your tab control. What you should end up with is an array of type List<Rectangle> (one list for each page) that you instantiate and fill in the form's Load event or its constructor (using the generated code).

I have to reiterate what Ed said, though. .Net forms can have a lot of controls on them without any real problems, so if you're running into problems stemming from having too many controls on the form, you might be better off redesigning the whole thing.

MusiGenesis