0

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:

error Message Screenshot

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!

Reginald
  • 23
  • 5
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it). Also what is `PopUpMessage`, put a break point on that line, debug and when it stops hover your mouse over the object, what is it? – Trevor Aug 30 '16 at 20:38
  • 1
    well, my issue isn't entirely focused on that error. It just so happens to appear after I add a line after the first error. PopUpMessage is the name of the project as I used it as an example to what I am trying to do. There are two projects called DisplayMessage and PopUpMessage in 1 solution. PopUpMessage has Form1 and I wanr to access it from DisplayMessage project so that it may appear when I click the menu item in Form1 of project DisplayMessage – Reginald Aug 31 '16 at 05:05

2 Answers2

1

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

Reginald
  • 23
  • 5
0

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.

Mark Hurd
  • 10,665
  • 10
  • 68
  • 101