Results 1 to 10 of 10

Thread: Duplicated form

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    165

    Duplicated form

    Opening main form with

    Dim fMain As New frmMain
    fMain.Show()

    Removed code from load/activate events of frmMain and only child, checked no other references but getting two copies of frmMain. Just using frmMain.show is ok, but shouldn't the original just give me just one instance?

    Cheers for any ideas.
    Last edited by xoggoth; May 21st, 2007 at 09:29 AM.

  2. #2
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Form created twice!

    Have you check if in the new procedure of the frmMain class you are not showing the form as well?

  3. #3
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Re: Duplicated form

    Are you putting
    Dim fMain As New frmMain
    fMain.Show()
    those lines in the code for frmMain itself? If so, you don't have to do that. It will automatically show the startup form of your project.
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    165

    Re: Duplicated form

    That was quick. Cheers!

    Seems not. In class thingy is 'MyBase.New(). Not sure what MyBase.new is supposed to do but commenting it out makes no difference.

  5. #5
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Duplicated form

    can you post your class frmMain?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    165

    Re: Duplicated form

    Not putting that in frmMain no, it is in the button click code of the Introduction form that is defined as the start up form. Tried with the frmMain event (frmMain_load) empty and no child form at all. Same problem.

    The class is what the conversion from VB6 and design mode changes have made of it. Not altered the code directly. Anyway:-

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> Partial Class frmMain
    #Region "Windows Form Designer generated code "
    <System.Diagnostics.DebuggerNonUserCode()> Public Sub New()
    MyBase.New()
    'This call is required by the Windows Form Designer.
    InitializeComponent()
    End Sub
    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
    If Disposing Then
    If Not components Is Nothing Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(Disposing)
    End Sub
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
    Public ToolTip1 As System.Windows.Forms.ToolTip
    Public dlgCommonDialog1Open As System.Windows.Forms.OpenFileDialog
    Public dlgCommonDialog1Save As System.Windows.Forms.SaveFileDialog
    Public dlgCommonDialog1Font As System.Windows.Forms.FontDialog
    Public dlgCommonDialog1Color As System.Windows.Forms.ColorDialog
    Public dlgCommonDialog1Print As System.Windows.Forms.PrintDialog
    Public WithEvents mnuDataInfo As System.Windows.Forms.ToolStripMenuItem
    blah blah
    Public WithEvents mnuWeb As System.Windows.Forms.ToolStripMenuItem
    Public WithEvents MainMenu1 As System.Windows.Forms.MenuStrip
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.components = New System.ComponentModel.Container
    Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmMain))
    Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
    Me.dlgCommonDialog1Open = New System.Windows.Forms.OpenFileDialog
    Me.dlgCommonDialog1Save = New System.Windows.Forms.SaveFileDialog
    Me.dlgCommonDialog1Font = New System.Windows.Forms.FontDialog
    Me.dlgCommonDialog1Color = New System.Windows.Forms.ColorDialog
    Me.dlgCommonDialog1Print = New System.Windows.Forms.PrintDialog
    Me.MainMenu1 = New System.Windows.Forms.MenuStrip
    Me.mnuData = New System.Windows.Forms.ToolStripMenuItem
    Me.mnuDataInfo = New System.Windows.Forms.ToolStripMenuItem
    blah blah
    Me.mnuWeb = New System.Windows.Forms.ToolStripMenuItem
    Me.ToolStrip1 = New System.Windows.Forms.ToolStrip
    Me.ToolStripButton0 = New System.Windows.Forms.ToolStripButton
    blah blah
    Me.ToolStripButton11 = New System.Windows.Forms.ToolStripButton
    Me.ToolbarBMP = New System.Windows.Forms.ImageList(Me.components)
    Me.TBImages = New System.Windows.Forms.ImageList(Me.components)
    Me.MainMenu1.SuspendLayout()
    Me.ToolStrip1.SuspendLayout()
    Me.SuspendLayout()
    '
    'MainMenu1
    '
    Me.MainMenu1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuData, Me.mnuView, Me.mnuOptions, Me.mnuWindow, Me.mnuHelp, Me.mnuWeb})
    Me.MainMenu1.Location = New System.Drawing.Point(0, 0)
    Me.MainMenu1.Name = "MainMenu1"
    Me.MainMenu1.Size = New System.Drawing.Size(535, 24)
    Me.MainMenu1.TabIndex = 2
    '
    'mnuData
    '
    Me.mnuData.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuDataInfo, Me.mnuDataInter, Me.mnuDataPrint, Me.mnuDataCopy, Me.mnuDataExit})
    Me.mnuData.MergeAction = System.Windows.Forms.MergeAction.Remove
    Me.mnuData.Name = "mnuData"
    Me.mnuData.Size = New System.Drawing.Size(43, 20)
    Me.mnuData.Text = "Data"
    '
    'mnuDataInfo
    '
    Me.mnuDataInfo.Name = "mnuDataInfo"
    Me.mnuDataInfo.Size = New System.Drawing.Size(178, 22)
    Me.mnuDataInfo.Text = "Information index"
    blah blah
    blah blah
    'mnuWeb
    '
    Me.mnuWeb.MergeAction = System.Windows.Forms.MergeAction.Remove
    Me.mnuWeb.Name = "mnuWeb"
    Me.mnuWeb.Size = New System.Drawing.Size(61, 20)
    Me.mnuWeb.Text = "Website"
    '
    'ToolStrip1
    '
    Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripButton0, Me.ToolStripButton1, Me.ToolStripButton2, Me.ToolStripButton3, Me.ToolStripButton4, Me.ToolStripButton5, Me.ToolStripButton6, Me.ToolStripButton7, Me.ToolStripButton8, Me.ToolStripButton9, Me.ToolStripButton10, Me.ToolStripButton11})
    Me.ToolStrip1.Location = New System.Drawing.Point(0, 24)
    Me.ToolStrip1.Name = "ToolStrip1"
    Me.ToolStrip1.Size = New System.Drawing.Size(535, 25)
    Me.ToolStrip1.TabIndex = 3
    Me.ToolStrip1.Text = "ToolStrip1"
    '
    'ToolStripButton0
    '
    Me.ToolStripButton0.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
    Me.ToolStripButton0.Image = CType(resources.GetObject("ToolStripButton0.Image"), System.Drawing.Image)
    Me.ToolStripButton0.ImageTransparentColor = System.Drawing.Color.Magenta
    Me.ToolStripButton0.Name = "ToolStripButton0"
    Me.ToolStripButton0.Size = New System.Drawing.Size(23, 22)
    Me.ToolStripButton0.Text = "ToolStripButton1"
    blah blah
    'ToolStripButton11
    '
    Me.ToolStripButton11.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
    Me.ToolStripButton11.Image = CType(resources.GetObject("ToolStripButton11.Image"), System.Drawing.Image)
    Me.ToolStripButton11.ImageTransparentColor = System.Drawing.Color.Magenta
    Me.ToolStripButton11.Name = "ToolStripButton11"
    Me.ToolStripButton11.Size = New System.Drawing.Size(23, 22)
    Me.ToolStripButton11.Text = "ToolStripButton12"
    '
    'ToolbarBMP
    '
    Me.ToolbarBMP.ImageStream = CType(resources.GetObject("ToolbarBMP.ImageStream"), System.Windows.Forms.ImageListStreamer)
    Me.ToolbarBMP.TransparentColor = System.Drawing.Color.Transparent
    Me.ToolbarBMP.Images.SetKeyName(0, "tb1.bmp")
    blah blah
    Me.ToolbarBMP.Images.SetKeyName(25, "tb63.bmp")
    '
    'TBImages
    '
    Me.TBImages.ImageStream = CType(resources.GetObject("TBImages.ImageStream"), System.Windows.Forms.ImageListStreamer)
    Me.TBImages.TransparentColor = System.Drawing.Color.Transparent
    Me.TBImages.Images.SetKeyName(0, "tb1.bmp")
    blah blah
    Me.TBImages.Images.SetKeyName(25, "tb63.bmp")
    '
    'frmMain
    '
    Me.BackColor = System.Drawing.SystemColors.AppWorkspace
    Me.ClientSize = New System.Drawing.Size(535, 276)
    Me.Controls.Add(Me.ToolStrip1)
    Me.Controls.Add(Me.MainMenu1)
    Me.Cursor = System.Windows.Forms.Cursors.Default
    Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
    Me.IsMdiContainer = True
    Me.Location = New System.Drawing.Point(11, 30)
    Me.Name = "frmMain"
    Me.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.MainMenu1.ResumeLayout(False)
    Me.MainMenu1.PerformLayout()
    Me.ToolStrip1.ResumeLayout(False)
    Me.ToolStrip1.PerformLayout()
    Me.ResumeLayout(False)
    Me.PerformLayout()

    End Sub
    Friend WithEvents ToolStrip1 As System.Windows.Forms.ToolStrip
    Friend WithEvents ToolStripButton0 As System.Windows.Forms.ToolStripButton
    blah blah
    Friend WithEvents ToolStripButton11 As System.Windows.Forms.ToolStripButton
    Friend WithEvents ToolbarBMP As System.Windows.Forms.ImageList
    Friend WithEvents TBImages As System.Windows.Forms.ImageList
    #End Region
    End Class

  7. #7
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Re: Duplicated form

    Could you please post the actual click event code, too?
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    165

    Re: Duplicated form

    I thought of bounce but the close should stop that?

    Private Sub Choice_4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Choice_4.Click

    ' Add any initialization after the InitializeComponent() call.

    Dim fMain As New frmMain
    fMain.Show()

    ' remove the intro form
    Me.Close()

    End Sub

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Duplicated form

    Does anything else trigger the button press? That's not a likely occurence in a button, but happens plenty with some other types of controls.

    One thing you might try is putting a breakpoint on the fMain.Show line. If you reach that breakpoint twice, then you just have to figure out how you got there each time. One will be a button press, the other will be an accident.

    If you only reach the breakpoint once, then something else is also showing frmMain. If this is 2005, then you may be showing the instance you created, and somewhere else you may be showing the default instance.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    165

    Re: Duplicated form

    Cheers shaggy. Immediately after the end of the frmMain_Load it does indeed go straight back to that line. Something else odd, the introduction form does not immediately show in the task bar, but if I just leave the debugger on the line one appears after about 5 seconds. Stepping on then produces the 2nd copy. Somehow I managed to get three once!

    I think I may have to start a clean project not based on a VB6 conversion and do a cut n paste job. The converted code just seems to have so many complications in the classes that you don't get if you do the same thing from scratch.

    ****Update!! Started again with clean project with no automatic update from VB6 stuff, so problem sorted! (really messy, some of the substitutions!!) Ta to all above for the help.
    Last edited by xoggoth; May 22nd, 2007 at 07:03 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width