Q. How can I close an MDI child form programatically, as opposed to the user closing the form with the top-right X?
Here is the scenerio.
- I have a listview control that lists inventory items.
- Each item contains the path to a .jpg file.
- When the user selects a listview item, I create a new MDI Child form that contains a scrollable picturebox.
This is working as fine as frog's hair. However, each time I select a new item, a new child form is created. I want only one child form created at any given time. Thus, when the user selects and item from the listview, I want to programmatically close the any previously created child form.
This is the code that is called from the Parent form when an item is selected from the listview.
Thanks in advance for your comments.
Here is the scenerio.
- I have a listview control that lists inventory items.
- Each item contains the path to a .jpg file.
- When the user selects a listview item, I create a new MDI Child form that contains a scrollable picturebox.
This is working as fine as frog's hair. However, each time I select a new item, a new child form is created. I want only one child form created at any given time. Thus, when the user selects and item from the listview, I want to programmatically close the any previously created child form.
This is the code that is called from the Parent form when an item is selected from the listview.
Code:
Sub CreateImageForm()
Try
Dim ImageForm As New frmImage
ImageForm.MdiParent = Me
ImageForm.Show()
ImageForm.Location = New Point(426, 2)
ImageForm.Text = ImgFile
ImageForm.Name = "TheImageForm"
Catch Excep As System.Exception
MessageBox.Show(Excep.Message, "CreateImageForm Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Thanks in advance for your comments.