I’m using VB 2008 express but this probably applies to all .net environments.
My question has to do with labels that do nothing. No events, and their text never changes. They just sit there above textboxes and other gizmos so the user knows what each doohickey is for. That’s their whole job. Simple. No code whatsoever. (Other than the code written by the form designer.)
My issue is there are so damned MANY of them! My app has multiple tabs on the same form, and each tab has a lot of objects and each has an associated label. Since I never bothered to name them, I now have a label with the name Label224. That’s right, 224 labels! It’s getting ridiculous. When I view the properties window, sometimes I wish to select an object by name using the drop down and they force a lot of scrolling.
QUESTION: Is there a way to make the sheer number of unnamed labels (or any type of object that isn’t referenced in code) less obtrusive during development?
I could load them in code of course. That would be fine, but it’s nice to lay them out graphically without the trial and error of running the code to see if the positioning is right.
A couple of things.
Set each label’s GenerateMember property to false:
This will prevent the Label from appearing in the code view combo boxes and intellisense.
Other than that, you just have too many controls.
You mentioned “tabs”, in which case, you can try to move each tab of stuff into a separate usercontrol, and then you are only loading a single usercontrol for each tab. It doesn’t reduce the number of controls, but it makes it a little more manageable.
The other “job” of a label is to provide mnemonic control activation for the next control in the tab order. If you are not using this, you can try “cheating” and getting rid of the labels all together, and “paint” the label next to each control in the container’s paint event. You could put the display of the label in a control’s tag property, and paint on that. Not necessarily the greatest suggestion.
Example: