Making multiple forms appear as one in VB.NET

后端 未结 4 1844
囚心锁ツ
囚心锁ツ 2021-01-23 16:11

I am writing a Windows Forms application in VB.NET. I have three forms: the main form, which shows a list of accounts, the account form which allows the user to view/edit the in

相关标签:
4条回答
  • 2021-01-23 16:49

    good morning there is another way . set property for second form to (top most) and use also

    from2.show();
    

    that make you switch between forms and keep form2 top other

    Thanks

    0 讨论(0)
  • 2021-01-23 17:00

    try using ShowDialog()

    Dim newForm as New AcctForm
    newForm.Location = Me.Location
    newForm.ShowDialog()
    Me.Close() <-- removed this
    
    0 讨论(0)
  • 2021-01-23 17:05

    I see this is already in the comments, but what I have done in this case in the past is build each "form" in the application as a custom control. Then I have one actual form, and navigation works by changing which custom control is currently loaded on the parent form. To move from one screen/view to another, you remove the current custom control from the form's controls collection and add the new custom control.

    I believe this is superior to manually setting the startup position and size, because you can use the form's .SuspendLayout()/.ResumeLayout() methods to hide the interim state, where there is no control loaded, from the user. This is harder to do when you want one form to be completely replaced by another.

    This also makes it easy to set certain form properties in one place and have them be consistent for the application. You can even have an area on the form with controls that will now show in every view.

    When using this pattern, I typically have each of my custom controls inherit from a common base. You may not have anything specific you will do with that base at the outset, but it almost always comes in handy later.

    Finally, switching to use this scheme is easier than you think. Just go to the code for the each of your current forms, and you will find that each class currently inherits from System.Windows.Forms.Form. Most of the time, all you really need to do is change them to inherit from System.Windows.Forms.Panel and you're most of the way there.

    0 讨论(0)
  • 2021-01-23 17:13

    As others have said, it may be better to redesign your application using custom controls or panels etc.

    However, to answer your question regarding the seemingly random location of your forms, the first thing to check is that each form has it's StartPosition property set to Manual.

    If your main form is resizable, then I would also add code to adjust newForm to the same size too.

    I hope that helps with your immediate issues; so that you can move on to redesigning the application!

    0 讨论(0)
提交回复
热议问题