开发者

Adding An Overloaded Constructor To A WinForm

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

 Dim dlgEd开发者_运维百科itChangeOrder 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


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜