-1

Am I practicing a good coding standard in .NET if I will create so many small forms that acts like a customize message box or input box?

I think that it will be hard to maintain it if I do it like that, but there isn't any way to customize a message box or input box freely.

This is an input box

enter image description here

And this is the form that I am using, just like a modified input box / message box

enter image description here

I also think that it is much better if I will not create a form just for that purpose, but I don't have a way to fully customize the message box or input box to make it like that. On the other hand, I am concern that if I create more than 10 of that small form if might be hard for me to maintain it in the future.

Cary Bondoc
  • 2,923
  • 4
  • 37
  • 60
  • Do you just need a name for `Add Teller` ?? – Vivek S. Nov 21 '15 at 05:24
  • @Vivek.S, I am also a little bit confuse about my question before so I revised it. Take a look and let me know if I can still do something with it. – Cary Bondoc Nov 21 '15 at 05:49
  • 1
    What's your question ? What you're trying to achieve? This questions seems unclear for me. OTOH If I understood correctly you can go for [UserControl](https://msdn.microsoft.com/en-us/library/aa302342.aspx) – Vivek S. Nov 21 '15 at 05:58
  • @Vivek.S I just checked the User Control and it looks promising, is it possible to put different user control in 1 form depending on the situation? For example if I click the btn_add it will show user_control_add in form1, then when I click btn_edit it will show user_control_edit in form1? – Cary Bondoc Nov 21 '15 at 06:26
  • 1
    @CaryBondoc yes you can decide at runtime which usercontrol you'd like to use based on your conditions at the time. – Andrew Mortimer Nov 21 '15 at 06:30
  • @Mort that's my question I just don't know how to say it like that. :D – Cary Bondoc Nov 21 '15 at 06:37

1 Answers1

1

This is a short example showing how you can add a UserControl at run-time. AddCtrl is your add UserControl. UpdateCtrl is your editing UserControl. You would still need to attach event handlers, using AddHandler.

Private Enum FormMode
    Adding
    Updating
End Enum

Private _formModeState As FormMode

Private Sub setupForm()

    'test adding
    _formModeState = FormMode.Adding
    setupInput(_formModeState)

    'test updating
    _formModeState = FormMode.Updating
    setupInput(_formModeState)

End Sub

Private Sub setupInput(thisFormMode As FormMode)
    Select Case thisFormMode
        Case FormMode.Adding
            Dim uc As New AddCtrl
            Me.Controls.Add(uc)
        Case FormMode.Updating
            Dim uc As New UpdateCtrl
            Me.Controls.Add(uc)
    End Select
End Sub
Andrew Mortimer
  • 2,380
  • 7
  • 31
  • 33