ListBox->Click->new Form

V

Viki

Hi All,

I want to do following; display Form2 after "click" on ListBox at Form1
(without ShowDialog) . Here is example - when I touch ListBox, form2 is
shown, but form1 is seen also. If I touch on Button2, there is shown only
Form2.


Where is problem.

Thanks Viki

--------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents ListBoxEx1 As New OpenNETCF.Windows.Forms.ListBoxEx
Friend WithEvents Button1 As New System.Windows.Forms.Button
Friend WithEvents Button2 As New System.Windows.Forms.Button
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

Public Sub New()
MyBase.New()
InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Dim mnu As New MenuItem
mnu.Text = "111"
MainMenu1.MenuItems.Add(mnu)
Me.Menu = Me.MainMenu1
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

Private Sub InitializeComponent()
Me.ListBoxEx1.Items.Add("AAA")
Me.ListBoxEx1.Items.Add("BBB")
Me.ListBoxEx1.Items.Add("CCC")
Me.ListBoxEx1.Location = New System.Drawing.Point(40, 30)
Me.ListBoxEx1.SelectedIndex = 1
Me.ListBoxEx1.Size = New System.Drawing.Size(170, 169)
Me.Button1.Location = New System.Drawing.Point(140, 220)
Me.Button1.Size = New System.Drawing.Size(60, 30)
Me.Button1.Text = "End"
Me.Button2.Location = New System.Drawing.Point(10, 220)
Me.Button2.Size = New System.Drawing.Size(60, 30)
Me.Button2.Text = "Button2"
Me.ClientSize = New System.Drawing.Size(244, 278)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.ListBoxEx1)
Me.Text = "Form1"
End Sub

Public Shared Sub Main()
Application.Run(New Form1)
End Sub

Private Sub ListBoxEx1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBoxEx1.Click
Dim frm As New Form2(Me)
frm.Show()
Me.Hide()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim frm As New Form2(Me)
frm.Show()
Me.Hide()
End Sub
End Class

Public Class Form2
Inherits System.Windows.Forms.Form
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents MainMenu2 As System.Windows.Forms.MainMenu
Private frm_main As Form

Public Sub New(ByVal frm As Form)
MyBase.New()
frm_main = frm
InitializeComponent()
Me.MainMenu2 = New System.Windows.Forms.MainMenu
Dim mnu As New MenuItem
mnu.Text = "2222"
MainMenu2.MenuItems.Add(mnu)
Me.Menu = Me.MainMenu2
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

Private Sub InitializeComponent()
Me.Button3 = New System.Windows.Forms.Button
Me.Button3.Location = New System.Drawing.Point(30, 100)
Me.Button3.Size = New System.Drawing.Size(70, 50)
Me.Button3.Text = "Button3"
Me.ClientSize = New System.Drawing.Size(244, 288)
Me.Controls.Add(Me.Button3)
Me.Text = "Form2"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
frm_main.Show()
Me.Close()
End Sub

End Class
-------------------
 
V

Viki

Thanks,
but problem continues. Although I have "hide form1", its Menu is shown.
Only when I touch to the screen, all is set correctly. ("Menu of Form2" is
already shown.)

Viki
 

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