Based on the code you posted, I assume that frmMain
represents your main form (which is the MDI parent form) and that frmPOSCashIn
and frmPOSTCashOut
are two MDI child forms. And based on the screenshot, the toolstrip seems to be included in frmMain
.
To wrap up the comments by jmcilhinney and Jimi:
- You should not explicitly create a
mainform
variable. You can just use Me
, since you are already executing within a frmMain
form instance.
- Since your
frmMain
instance itself is the MDI container (its IsMdiContainer
property is set to True
), it itself should be used as the value for the MdiParent
property of your child forms (whose IsMdiContainer
properties are set to False
). (The MDI architecture allows only one level of hierarchy. You cannot nest MDI container forms as MDI children in an(other) MDI container form. So you should never use the MdiParent
property of an MDI container form.)
- You can declare your MDI child form variables inside the If-block. And in each block, you should only declare the variable that you actually need.
Something like this:
Private Sub ToolStrip_Click(sender As Object, e As EventArgs) Handles ToolStrip.Click
If CashIn.Selected Then
Dim formcashin As New frmPOSCashIn
formcashin.MdiParent = Me
formcashin.Show()
ElseIf Cashout.Selected Then
Dim formcashout As New frmPOSTCashout
formcashout.MdiParent = Me
formcashout.Show()
End If
End Sub
If you are new to this stuff, I would suggest that you first check out some tutorials/walkthroughs in the Microsoft documentation or other sources on the Internet.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…