views:

31

answers:

1

I have created a dialog as a winform and am calling that winform like this:

 Dim dlgEditChangeOrder As New dgEditChangeOrder
        Dim dlgResult As DialogResult

        dlgResult = dlgEditChangeOrder.ShowDialog

...pretty simple. I want to be able to set the visiblility of a control on the win form when the win form is called. I would like to do this as a constructor so I could write the following....

  Dim dlgEditChangeOrder As New dgEditChangeOrder(visibleIsTrue)

Can someone give me the contructor code to make this happen? The reason I am concerned is I dunno if its legal to do this inside a winform since the winform is loaded bby the precreated IntializeComponent() function

+5  A: 

It is perfectly acceptable to overload constructors. Just make sure to call InitializeComponent() in your overloaded constructor, as it's required to setup the form.

However, as long as you do this, you are free to overload the constructor (or just change the one that's there).


Edit:

Just add this in your code behind:

Public Sub New(ByVal isVisible As Boolean)
    ' This call is required by the designer.
    InitializeComponent()

    ' Do what you want with isVisible here

End Sub

If you want to have a default constructor, too, you can add that (it's not required, however).

Reed Copsey
I dont see a constructor in the code behind. Do I have to create
Nick LaMarca
Do I have to create Public Sub New() and Public Sub New(Byval v as Boolean) ?
Nick LaMarca
@Nick: You don't need both (unless you want it) - just the boolean. If you don't have a default constructor, you'll always be forced to specify the boolean
Reed Copsey
@saurabh: You aren't required to have a default constructor for a windows form - it's perfectly legal to only have a custom constructor with parameters.
Reed Copsey