Question What's the best way to duplicate a form several times?

Iketh

Active member
Joined
Nov 23, 2009
Messages
40
Programming Experience
Beginner
I have one form that needs to act as a template for 4 forms, each with its own set of variables.

Do I need to set them up like:

VB.NET:
Expand Collapse Copy
Public frmSlot1, frmSlot2, frmSlot3, frmSlot4 As New frmSlotSetup

Or create an array?

VB.NET:
Expand Collapse Copy
Public frmSlot(3) As frmSlotSetup

:confused:
 
How about:
VB.NET:
Expand Collapse Copy
Dim slotForms As New List(Of frmSlotSetup)
Now you can add/remove them as needed. :cool:
 
well, what i'm wondering is which method makes it easiest to manage the forms?

I want to write one set of code that can handle all 4 forms (depending on which form is being accessed), instead of writing 4 blocks of identical code to interact with each.

EDIT: And there will be a constant of 4 forms, never more, never less.
 
Inheritance appears to counter my goal. The link says the controls on the inherited form are locked?

What I wanna know is when I set the array frmSlot(3) and then the user chooses to work with frmSlot(1), can I say frmSlotSetup = frmSlot(1) to load all the settings of the controls from frmSlot(1)? Or do I need to specify every control in frmSlotSetup to copy the selections of the ones in frmSlot(1)? And is this even the correct way of handling it?

The user will rotate (and even have all 4 forms open at once if needed) and interact with each.

I'm not at this point of construction in the program yet and I'm trying to get an idea before I get there.
 
You will be able to code for each of the forms and there controls seperately as you want. Also since they are seperate forms, you wont need to use an array. I suggest atleast making a small test app with a couple forms to give it a try, I think it will meet your needs and is pretty easy.
 
Sorry, I'm not explaining myself very well. I don't want to code for each form. Each form will have identical code, so I'd rather use an array if possible so I don't have 4 sets of identical code.

Ill have one set of code using arrays that will handle each form, depending on which the user interacts with. Is this possible?
 
Do you mean based on the user credentials the forms respond differently, but if this were the case you would only need 1 form. I am getting close?, or try to describe it again, and be very detailed.
 
Each form has identical controls and identical code handling each control. Each form is a profile that is customized by the user.

The user runs a test using the selections of a profile (form). Then the user can make different selections on another form and run a test and compare the results from both forms after the tests are complete.

The results are placed on the startup form. However, the profile forms need not be closed. They are to remain open if the user chooses to make quick adjustments to the profile and run more tests.

I don't want to make 4 sections of identical code because I'll have to apply an edit in code to all 4 sections every time, and I'll be making edits often. In my mind I don't understand how all 4 forms can be open at once (using an array) and the event handlers for the template form respond correctly to each profile form. But maybe it does, I'll just have to play when I get to it.
 
So, now that I'm understanding my own needs better, I suppose I should have asked from the beginning whether or not all event handlers for a template form are copied with an array...
 
They all act independent from each other - they are seperate objects. Yes sometimes it is better to pose a question on how to do something rather than here is what I am doing - the wrong way(poss).
 
Well I've gotten to the point that I can play with the forms. I'm using this line to declare them:

VB.NET:
Expand Collapse Copy
Public frmProfile(3) As frmProfileSetup

I'm not using "New" because it says I can't with an array.... and so then I get this error when i try to access the very first control on frmProfile(0):

"NullReferenceException was unhandled. Object reference not set to an instance of an object."

Should I just go back to frmProfile1, frmProfile2, etc... ?
 
Back
Top