Reputation: 23
I'm trying to see if I was able to link a menu item (For sake of examples: DisplayProject) in my main Form1 to a Form1 in another project (Project name: PopUpMessage) that is in the same solution.
I already added it from the reference option, so I am able to use the object in my main Form1.
I thought maybe by declaring the following it would work within this menuitem from MenuStrip. I wrapped this in a "try/catch" by the way which is why I get that pop up windows:
Try
PopUpMessage.Form1.ActiveForm.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
I am declaring this in DisplayMessage project Form1 menustrip item. However I get the error:
As daring as I am, I decided to do the following:
Try
PopUpMessage.Form1.ActiveForm.Visible = False
PopUpMessage.Form1.ActiveForm.ShowDialog()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Then I go the following error: Second Error Message
Anyone has an idea what can be done? I'm kinda new to this type of methods used in VB .NET.
Thank you in advance!
Upvotes: 0
Views: 39
Reputation: 10931
You've found the right answer, but to explain what you saw:
Form.ActiveForm
is a Shared
Property
and returns the current foreground form, if there is one, not specific to your Class
.
Then, either ShowDialog
correctly complains you're trying to redisplay an already visible form or you're trying to execute a method on Nothing
.
Upvotes: 0
Reputation: 23
Already found the way to do it. For future reference it's:
Dim PopUpMessage As New PopUpMessage.Form1
Try
PopUpMessage.Show()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
That was all...
Upvotes: 1