Desktop is showing when form is closed

jdy0803

Well-known member
Joined
Sep 9, 2012
Messages
73
Location
Santa Clarita
Programming Experience
10+
In the main window of my program, load form and display as modal like following.
Dim frm As New form1
frm.ShowDialog()
When close from form1 by Me.Dispose(), desktop(background) is showing in a flash.
It looks like this.
mainform=>form1=>close form1=>(display desktop)=>mainform
Flickering occurs at (display desktop)

I don't know why this happens.
Can anybody give me some advice?

Here is my code.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New form2
frm.ShowDialog(Me)
End Sub
End Class


Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Dispose()
End Sub
End Class
 
Last edited:
Flickering occurs at (display desktop)

I don't know why this happens.
I can't see that, and can't think of any reason why, but you may have a memory leak in your program. What if user closes that dialog in any other way than clicking your button? If that happens that dialog object will not be disposed. Your "close" button should call the Close method, and in code after your ShowDialog call you should call frm.Dispose - that will ensure no matter how the dialog returns it will be disposed.
 
You will be able to see that symptom if you try like this.
1. Open windows explorer on the background
2. Run Program
3. Click Button1 on the form1
4. Click Button1 on the Form2

Repeat step3 and step4 many times and then you will see the windows explorer in a flash on the background.
The codes inside quote are all, so memory leak doesn't occur.
I tried this in several computer and occurs in all computer.
 
No, this doesn't happen on any of my computers.
The codes inside quote are all, so memory leak doesn't occur.
To fix the memory leak in your code you have to do as I explained. The memory leak will occur under the conditions I also explained.
 
Back
Top