-1

The problem I'm having is that I'm using a menustrip on my home screen, and all of the tabs/buttons are working except for one, where instead of opening the form I want it to, it opens the standard, plain one that you see before adding anything to the form. If I change the form identifier that I want it to open then it works, just not with this form. Does anybody know why? The top subroutine here is the problematic one, the one below is a working one.

Private Sub SupportIncidentsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SupportIncidentsToolStripMenuItem.Click 
    Dim f As frmIncidents
    f = New frmIncidents(con, AccCon)
    f.Show()
End Sub


Private Sub EmailLogsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EmailLogsToolStripMenuItem.Click
    Dim f As frmEmailLogs
    f = New frmEmailLogs(con)
    f.MdiParent = Me
    f.Show()
End Sub
Ezi
  • 2,132
  • 8
  • 30
  • 58
David
  • 2,058
  • 4
  • 19
  • 45
  • what happens when you debug the code and step through the code..? could this be a Parent, Owner Issue.. – MethodMan Jun 29 '16 at 19:54

2 Answers2

2

With this line your are calling the constructor that takes 2 arguments

f = New frmIncidents(con, AccCon)

So in your frmIncidents class you have manually added a constructor like this one

Public Sub frmIncidents(con as WhatEverConIs, Acon as WhatEverAConIs)


End Sub

But every form constructor should call the InitializeComponent method that is the method automatically created by the WinForms Designer with the declaration of the forms controls and the relative properties set through the designer.

See Very simple definition of InitializeComponent

Having added this constructor manually and looking at the blank form presented when you call the Show method I am pretty sure that you have forgotten to add the call to InitializeComponent

Public Sub frmIncidents(con as WhatEverConIs, Acon as WhatEverAConIs)

    InitializeComponent()
End Sub
Community
  • 1
  • 1
Steve
  • 203,265
  • 19
  • 210
  • 265
  • 1
    so if I add in InitializeComponent() and keep the rest of the code the same, you're saying that that should do it? – David Jun 29 '16 at 20:21
  • Of course.... without that call the form is empty, InitializeComponent is located in a file named after your form class and with the .Designer.vb. Normally this file is hidden but you can view it pressing the Show All Files button on the Solution Explorer window. Open it and you will see all the code required to build your user interface as prepared through the WinForms designer – Steve Jun 29 '16 at 20:29
0

In the end, the answer was that I had two constructors in my class that were overwriting one another, so the plain form was being shown, rather than the form I designed that the first constructor would have displayed.

David
  • 2,058
  • 4
  • 19
  • 45