José Ferreira José Ferreira - 24 days ago 13
Vb.net Question

Send Parameter via new() or pre-set properties before calling the new form?

I would really appreciate your advice on the following:
I'm working on Windows forms using VB.NET (even though the language is irrelevant to the question at hand).
I've got a main form and wish to call out another one, however depending on a given variable I need the text on some of the new form's elements to change as well as disable some of its controls.
There are two ways I see of doing it:


  1. Send a parameter from the main form and have some logic on the second form to deal with everything on load.



Main Form:

dim newform as new frmcalculate(byval type as string)


New Form:

public sub getexplanation(byval type as string)
select type
case "Sum"
lblexplanation.text = "this is a sum"
case "Subtraction"
lblexplanation.text = "this is a subtraction"
End sub



  1. Set exactly what I want on the main form before calling the new form.
    i.e:

    dim newform as new frmcalculate()
    newform.lblexplanation.text = "This is a sum"



I hope I've managed to explain it correctly.
I'm still new at this especially getting the formats right on Stackoverflow.

Answer

In the first approach the code is best managed and organized for further editing. So each form has it own code.

It is not best practice to use second approach. (Editing a form designer from another one)