How to create a form instance at hidden state?

Ö

Özden Irmak

Hello,

In my VB.Net application I create a new instance of my form like :

NewForm = new MyNewForm()

But with this line, this new form is automatically shown. I want it to be
hidden at the start...

Adding a line after this line like :

NewForm.Hide() or NewForm.Visible = false

didn't help. Putting this line to this new form's load event didn't help
either.

Sub Form_Load()

Me.Hide()

End Sub

How can I achieve this?

Regards,

Özden
 
A

Armin Zingler

Özden Irmak said:
Hello,

In my VB.Net application I create a new instance of my form like :

NewForm = new MyNewForm()

But with this line, this new form is automatically shown. I want it
to be hidden at the start...

Adding a line after this line like :

NewForm.Hide() or NewForm.Visible = false

didn't help. Putting this line to this new form's load event didn't
help either.

Sub Form_Load()

Me.Hide()

End Sub

How can I achieve this?

Regards,

Özden

There must be code that shows the form. The line "...new myneworm" itself
does not show the Form. Set a breakpoint in Form_Load and examine the
callstack to find out where and why the form is shown.
 
C

Cor

Hi Ozden,

If you not get something nicer you can use this
(But you have to put make that me.hide conditional otherwise you see it
never more)
:)
Cor

\\\
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Minimized
End Sub

Private Sub Form2_VisibleChanged(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.VisibleChanged
Me.Hide()
End Sub
///

Cor
 
Ö

Özden Irmak

Hello,

Thanks for this advice I'll keep in my pocket...

This solution does allow the form to make something like flash at the
beginning so I probably will be looking for a better solution...

Thanks again...

Özden
 
H

Herfried K. Wagner [MVP]

* "Özden Irmak said:
In my VB.Net application I create a new instance of my form like :

NewForm = new MyNewForm()

But with this line, this new form is automatically shown. I want it to be
hidden at the start...

It should not be shown automatically. Post the code from the form's
constructor.
 
Ö

Özden Irmak

Here's the code generated by windows forms designer (VS.Net 2002) :

Friend ContainerControl As Control = Nothing 'ContainerControl where other
controls are contained

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

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

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

Friend WithEvents PGrid As System.Windows.Forms.PropertyGrid

Friend WithEvents Splt As System.Windows.Forms.Splitter

Friend WithEvents TBar As System.Windows.Forms.ToolBar

Friend WithEvents ImgLst As System.Windows.Forms.ImageList

Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton

Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton

Friend WithEvents OFile As System.Windows.Forms.OpenFileDialog

Friend WithEvents SFile As System.Windows.Forms.SaveFileDialog

Friend WithEvents CListBox As Tranztec.Windows.Forms.ToolboxService

Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container()

Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(FrmToolBox))

Me.PGrid = New System.Windows.Forms.PropertyGrid()

Me.Splt = New System.Windows.Forms.Splitter()

Me.TBar = New System.Windows.Forms.ToolBar()

Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton()

Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton()

Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton()

Me.ImgLst = New System.Windows.Forms.ImageList(Me.components)

Me.OFile = New System.Windows.Forms.OpenFileDialog()

Me.SFile = New System.Windows.Forms.SaveFileDialog()

Me.CListBox = New Tranztec.Windows.Forms.ToolboxService()

Me.SuspendLayout()

'

'PGrid

'

Me.PGrid.BackColor = System.Drawing.SystemColors.Control

Me.PGrid.CommandsVisibleIfAvailable = True

Me.PGrid.Dock = System.Windows.Forms.DockStyle.Bottom

Me.PGrid.HelpVisible = False

Me.PGrid.LargeButtons = False

Me.PGrid.LineColor = System.Drawing.SystemColors.ScrollBar

Me.PGrid.Location = New System.Drawing.Point(0, 240)

Me.PGrid.Name = "PGrid"

Me.PGrid.Size = New System.Drawing.Size(242, 248)

Me.PGrid.TabIndex = 0

Me.PGrid.Text = "PropertyGrid"

Me.PGrid.ToolbarVisible = False

Me.PGrid.ViewBackColor = System.Drawing.SystemColors.Window

Me.PGrid.ViewForeColor = System.Drawing.SystemColors.WindowText

'

'Splt

'

Me.Splt.Dock = System.Windows.Forms.DockStyle.Bottom

Me.Splt.Location = New System.Drawing.Point(0, 236)

Me.Splt.Name = "Splt"

Me.Splt.Size = New System.Drawing.Size(242, 4)

Me.Splt.TabIndex = 1

Me.Splt.TabStop = False

'

'TBar

'

Me.TBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat

Me.TBar.Buttons.AddRange(New System.Windows.Forms.ToolBarButton()
{Me.ToolBarButton3, Me.ToolBarButton1, Me.ToolBarButton2})

Me.TBar.DropDownArrows = True

Me.TBar.ImageList = Me.ImgLst

Me.TBar.Name = "TBar"

Me.TBar.ShowToolTips = True

Me.TBar.Size = New System.Drawing.Size(242, 25)

Me.TBar.TabIndex = 2

Me.TBar.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right

'

'ToolBarButton3

'

Me.ToolBarButton3.ImageIndex = 0

Me.ToolBarButton3.Text = "New"

Me.ToolBarButton3.ToolTipText = "Clears the design surface for a new
design..."

'

'ToolBarButton1

'

Me.ToolBarButton1.ImageIndex = 1

Me.ToolBarButton1.Text = "Open"

Me.ToolBarButton1.ToolTipText = "Open a previously saved layout..."

'

'ToolBarButton2

'

Me.ToolBarButton2.ImageIndex = 2

Me.ToolBarButton2.Text = "Save"

Me.ToolBarButton2.ToolTipText = "Save the current designed layout..."

'

'ImgLst

'

Me.ImgLst.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit

Me.ImgLst.ImageSize = New System.Drawing.Size(16, 16)

Me.ImgLst.ImageStream = CType(resources.GetObject("ImgLst.ImageStream"),
System.Windows.Forms.ImageListStreamer)

Me.ImgLst.TransparentColor = System.Drawing.Color.Transparent

'

'CListBox

'

Me.CListBox.BackColor = System.Drawing.SystemColors.Control

Me.CListBox.BorderStyle = System.Windows.Forms.BorderStyle.None

Me.CListBox.Dock = System.Windows.Forms.DockStyle.Fill

Me.CListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable

Me.CListBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(162,
Byte))

Me.CListBox.IntegralHeight = False

Me.CListBox.Location = New System.Drawing.Point(0, 25)

Me.CListBox.Name = "CListBox"

Me.CListBox.SelectedCategory = Nothing

Me.CListBox.Size = New System.Drawing.Size(242, 211)

Me.CListBox.TabIndex = 4

'

'FrmToolBox

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(242, 488)

Me.ControlBox = False

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CListBox,
Me.TBar, Me.Splt, Me.PGrid})

Me.Name = "FrmToolBox"

Me.ShowInTaskbar = False

Me.Text = "Designer ToolBox"

Me.WindowState = System.Windows.Forms.FormWindowState.Minimized

Me.ResumeLayout(False)

End Sub

#End Region
 
Ö

Özden Irmak

Hello,

I found the problem...My control's property, which sometimes shows the form,
was showing the form...

Thank you all...

Özden

Özden Irmak said:
Here's the code generated by windows forms designer (VS.Net 2002) :

Friend ContainerControl As Control = Nothing 'ContainerControl where other
controls are contained

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

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

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

Friend WithEvents PGrid As System.Windows.Forms.PropertyGrid

Friend WithEvents Splt As System.Windows.Forms.Splitter

Friend WithEvents TBar As System.Windows.Forms.ToolBar

Friend WithEvents ImgLst As System.Windows.Forms.ImageList

Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton

Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton

Friend WithEvents OFile As System.Windows.Forms.OpenFileDialog

Friend WithEvents SFile As System.Windows.Forms.SaveFileDialog

Friend WithEvents CListBox As Tranztec.Windows.Forms.ToolboxService

Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container()

Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(FrmToolBox))

Me.PGrid = New System.Windows.Forms.PropertyGrid()

Me.Splt = New System.Windows.Forms.Splitter()

Me.TBar = New System.Windows.Forms.ToolBar()

Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton()

Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton()

Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton()

Me.ImgLst = New System.Windows.Forms.ImageList(Me.components)

Me.OFile = New System.Windows.Forms.OpenFileDialog()

Me.SFile = New System.Windows.Forms.SaveFileDialog()

Me.CListBox = New Tranztec.Windows.Forms.ToolboxService()

Me.SuspendLayout()

'

'PGrid

'

Me.PGrid.BackColor = System.Drawing.SystemColors.Control

Me.PGrid.CommandsVisibleIfAvailable = True

Me.PGrid.Dock = System.Windows.Forms.DockStyle.Bottom

Me.PGrid.HelpVisible = False

Me.PGrid.LargeButtons = False

Me.PGrid.LineColor = System.Drawing.SystemColors.ScrollBar

Me.PGrid.Location = New System.Drawing.Point(0, 240)

Me.PGrid.Name = "PGrid"

Me.PGrid.Size = New System.Drawing.Size(242, 248)

Me.PGrid.TabIndex = 0

Me.PGrid.Text = "PropertyGrid"

Me.PGrid.ToolbarVisible = False

Me.PGrid.ViewBackColor = System.Drawing.SystemColors.Window

Me.PGrid.ViewForeColor = System.Drawing.SystemColors.WindowText

'

'Splt

'

Me.Splt.Dock = System.Windows.Forms.DockStyle.Bottom

Me.Splt.Location = New System.Drawing.Point(0, 236)

Me.Splt.Name = "Splt"

Me.Splt.Size = New System.Drawing.Size(242, 4)

Me.Splt.TabIndex = 1

Me.Splt.TabStop = False

'

'TBar

'

Me.TBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat

Me.TBar.Buttons.AddRange(New System.Windows.Forms.ToolBarButton()
{Me.ToolBarButton3, Me.ToolBarButton1, Me.ToolBarButton2})

Me.TBar.DropDownArrows = True

Me.TBar.ImageList = Me.ImgLst

Me.TBar.Name = "TBar"

Me.TBar.ShowToolTips = True

Me.TBar.Size = New System.Drawing.Size(242, 25)

Me.TBar.TabIndex = 2

Me.TBar.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right

'

'ToolBarButton3

'

Me.ToolBarButton3.ImageIndex = 0

Me.ToolBarButton3.Text = "New"

Me.ToolBarButton3.ToolTipText = "Clears the design surface for a new
design..."

'

'ToolBarButton1

'

Me.ToolBarButton1.ImageIndex = 1

Me.ToolBarButton1.Text = "Open"

Me.ToolBarButton1.ToolTipText = "Open a previously saved layout..."

'

'ToolBarButton2

'

Me.ToolBarButton2.ImageIndex = 2

Me.ToolBarButton2.Text = "Save"

Me.ToolBarButton2.ToolTipText = "Save the current designed layout..."

'

'ImgLst

'

Me.ImgLst.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit

Me.ImgLst.ImageSize = New System.Drawing.Size(16, 16)

Me.ImgLst.ImageStream = CType(resources.GetObject("ImgLst.ImageStream"),
System.Windows.Forms.ImageListStreamer)

Me.ImgLst.TransparentColor = System.Drawing.Color.Transparent

'

'CListBox

'

Me.CListBox.BackColor = System.Drawing.SystemColors.Control

Me.CListBox.BorderStyle = System.Windows.Forms.BorderStyle.None

Me.CListBox.Dock = System.Windows.Forms.DockStyle.Fill

Me.CListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable

Me.CListBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(162,
Byte))

Me.CListBox.IntegralHeight = False

Me.CListBox.Location = New System.Drawing.Point(0, 25)

Me.CListBox.Name = "CListBox"

Me.CListBox.SelectedCategory = Nothing

Me.CListBox.Size = New System.Drawing.Size(242, 211)

Me.CListBox.TabIndex = 4

'

'FrmToolBox

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(242, 488)

Me.ControlBox = False

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CListBox,
Me.TBar, Me.Splt, Me.PGrid})

Me.Name = "FrmToolBox"

Me.ShowInTaskbar = False

Me.Text = "Designer ToolBox"

Me.WindowState = System.Windows.Forms.FormWindowState.Minimized

Me.ResumeLayout(False)

End Sub

#End Region
 
A

Andrew \(Infragistics\)

To find out what is causing it to become visible, catch the
VisibleChanged of the form and put a break point there. Then just look at
the call stack and see what is causing the form to become visible. It is
likely the Tranztec.Windows.Forms.ToolboxService control (whatever that is)
is either explicitly making it visible or using something like wm_redraw on
the form causing it to become visible. Alternatively you may be doing
something in response to an event that is invoked as a result of a property
being initialized that is causing the form to be displayed.

Özden Irmak said:
Here's the code generated by windows forms designer (VS.Net 2002) :

Friend ContainerControl As Control = Nothing 'ContainerControl where other
controls are contained

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

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

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

Friend WithEvents PGrid As System.Windows.Forms.PropertyGrid

Friend WithEvents Splt As System.Windows.Forms.Splitter

Friend WithEvents TBar As System.Windows.Forms.ToolBar

Friend WithEvents ImgLst As System.Windows.Forms.ImageList

Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton

Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton

Friend WithEvents OFile As System.Windows.Forms.OpenFileDialog

Friend WithEvents SFile As System.Windows.Forms.SaveFileDialog

Friend WithEvents CListBox As Tranztec.Windows.Forms.ToolboxService

Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container()

Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(FrmToolBox))

Me.PGrid = New System.Windows.Forms.PropertyGrid()

Me.Splt = New System.Windows.Forms.Splitter()

Me.TBar = New System.Windows.Forms.ToolBar()

Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton()

Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton()

Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton()

Me.ImgLst = New System.Windows.Forms.ImageList(Me.components)

Me.OFile = New System.Windows.Forms.OpenFileDialog()

Me.SFile = New System.Windows.Forms.SaveFileDialog()

Me.CListBox = New Tranztec.Windows.Forms.ToolboxService()

Me.SuspendLayout()

'

'PGrid

'

Me.PGrid.BackColor = System.Drawing.SystemColors.Control

Me.PGrid.CommandsVisibleIfAvailable = True

Me.PGrid.Dock = System.Windows.Forms.DockStyle.Bottom

Me.PGrid.HelpVisible = False

Me.PGrid.LargeButtons = False

Me.PGrid.LineColor = System.Drawing.SystemColors.ScrollBar

Me.PGrid.Location = New System.Drawing.Point(0, 240)

Me.PGrid.Name = "PGrid"

Me.PGrid.Size = New System.Drawing.Size(242, 248)

Me.PGrid.TabIndex = 0

Me.PGrid.Text = "PropertyGrid"

Me.PGrid.ToolbarVisible = False

Me.PGrid.ViewBackColor = System.Drawing.SystemColors.Window

Me.PGrid.ViewForeColor = System.Drawing.SystemColors.WindowText

'

'Splt

'

Me.Splt.Dock = System.Windows.Forms.DockStyle.Bottom

Me.Splt.Location = New System.Drawing.Point(0, 236)

Me.Splt.Name = "Splt"

Me.Splt.Size = New System.Drawing.Size(242, 4)

Me.Splt.TabIndex = 1

Me.Splt.TabStop = False

'

'TBar

'

Me.TBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat

Me.TBar.Buttons.AddRange(New System.Windows.Forms.ToolBarButton()
{Me.ToolBarButton3, Me.ToolBarButton1, Me.ToolBarButton2})

Me.TBar.DropDownArrows = True

Me.TBar.ImageList = Me.ImgLst

Me.TBar.Name = "TBar"

Me.TBar.ShowToolTips = True

Me.TBar.Size = New System.Drawing.Size(242, 25)

Me.TBar.TabIndex = 2

Me.TBar.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right

'

'ToolBarButton3

'

Me.ToolBarButton3.ImageIndex = 0

Me.ToolBarButton3.Text = "New"

Me.ToolBarButton3.ToolTipText = "Clears the design surface for a new
design..."

'

'ToolBarButton1

'

Me.ToolBarButton1.ImageIndex = 1

Me.ToolBarButton1.Text = "Open"

Me.ToolBarButton1.ToolTipText = "Open a previously saved layout..."

'

'ToolBarButton2

'

Me.ToolBarButton2.ImageIndex = 2

Me.ToolBarButton2.Text = "Save"

Me.ToolBarButton2.ToolTipText = "Save the current designed layout..."

'

'ImgLst

'

Me.ImgLst.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit

Me.ImgLst.ImageSize = New System.Drawing.Size(16, 16)

Me.ImgLst.ImageStream = CType(resources.GetObject("ImgLst.ImageStream"),
System.Windows.Forms.ImageListStreamer)

Me.ImgLst.TransparentColor = System.Drawing.Color.Transparent

'

'CListBox

'

Me.CListBox.BackColor = System.Drawing.SystemColors.Control

Me.CListBox.BorderStyle = System.Windows.Forms.BorderStyle.None

Me.CListBox.Dock = System.Windows.Forms.DockStyle.Fill

Me.CListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable

Me.CListBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(162,
Byte))

Me.CListBox.IntegralHeight = False

Me.CListBox.Location = New System.Drawing.Point(0, 25)

Me.CListBox.Name = "CListBox"

Me.CListBox.SelectedCategory = Nothing

Me.CListBox.Size = New System.Drawing.Size(242, 211)

Me.CListBox.TabIndex = 4

'

'FrmToolBox

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(242, 488)

Me.ControlBox = False

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.CListBox,
Me.TBar, Me.Splt, Me.PGrid})

Me.Name = "FrmToolBox"

Me.ShowInTaskbar = False

Me.Text = "Designer ToolBox"

Me.WindowState = System.Windows.Forms.FormWindowState.Minimized

Me.ResumeLayout(False)

End Sub

#End Region
 
H

Hakan Gok

Hi Ozden,
This is a tricky way however it may be helpful:

Dim NewForm As New Form2
NewForm.ShowInTaskbar = False
NewForm.FormBorderStyle = FormBorderStyle.None
NewForm.Width = 0
NewForm.Height = 0
NewForm.Show()

Try this code.

Kolay gelsin....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top