carpal tunnel
Registered: 14/01/2002
Posts: 2858
Loc: Atlanta, GA
|
Quote: To adress Andy first, pointers in C# are normally avoided.
True in the strictest sense; however, the concept is that you store a REFERENCE to the object (or variable) and then use it later. While in simpler languages this can only be done with a pointer, in oop languages the concept of an "instance" came along and so did variables to reference them- essentially giving you the same power as a pointer. Think of an object reference as a pointer++, because under the hood, that's what it really is- a pointer to the memory where the data is stored plus a pointer to the structure of how to understand that data. The details of this really aren't that important, but the point is that while .net languages do not have pointers, you can still pass around references to objects. So you could create an array of controls and then track your controls with it:
Code:
myControls[0]=control1; myControls[1]=control2; ...
Of course, that's what self.Controls is already doing- only with EVERY control, not just the one's in which you're interested.
Quote: As far as the example Jeff, do you know perhaps a better way to be doing this to avoid loops?
My question would be, why would you not want to use a loop? Since it is self contained in the method, the calling code will be very clear and this kind of loop will not consumer many resources. IMHO, this is probably the most instutive and clear from a readability standpoint- probably more clear (and less prone to programming error) than trying to track a list of object references- if only because your code will all be isolated to one method rather than having to create and maintain an array. So I guess the short answer is that I don't know a better way (but someone else might) . . .
Quote: I want to have a situation where there can be a maximum of 8 groupboxes in the form, but if they are not all needed, less will be shown. Each groupbox contains identical controls (for example sake) to modify a text file 0-7.
Honestly, if this were a problem I had to address, I'd probably create a User Control that was self contained and knew how to handle all of the editing. Then I'd create a class that could manage a set of these controls, position them correctly, and handle the proper files. This would allow you to prevent duplicate code and keep all of the complex logic of dealing with missing group boxes all together. However, if you are just learning this might be a bit advanced. It depends on your background with oop and creating custom controls.
Quote: And thus now having the program only show controls for files 0,1,3,4,5,6,7, and with no visible gap between 1 and 3 because the controls that normally would be shown for 2 are now modifying 3 and such.
The one thing you can consider for handeling boxes appearing without gaps is how they are "docked". If you have a list and they are all docked to the "top", making one invisible (or deleting it) would cause the others to "snap" up. Another option might be a tabbed interface where each box goes on its own tab. In this scenerio it is easy to hide or delete any of the tabs and there would be no "gap".
I hopes this is helpful- I fear I might be confusing the issue more! 
_________________________
-Jeff Rome did not create a great empire by having meetings; they did it by killing all those who opposed them.
|