Need Help with Form Instancing

S

Scott H

Hi All,

Coming from VB6, there was a bit of a difference in the way you
display a form, I Thought I'd nailed instanciating a form, but I'm
quite stuck with something that doesn't make sense.

my main form has an event handler that instanciates a small popup form
each time it fires, the code inside the handler is:

Dim f As New frmInfoPopup
f.Show()

as soon as the End Sub of the handler is reached, it locks that form,
and doesn't repaint it, if I attempt to close it, it says its not
responding, at some point I got some mention of a
"WindowsFormParkingWindow" which wouldn't close.

I have other event handlers that instansiate a form just the same, and
they work fine.

Just as an experiment I added this to the handler:

do while f.visible
application.doevents
loop

and all is well, except that it stays in that loop using up lots of
CPU time until the popup window is closed.

BTW, the actual frmInfoPopup form/class has no code inside.

Any Help?

Scott
 
C

Cor

Hi Scott,

I have a sample still in my clipboard, I only have to do right click and
paste
I was sending this to Whitesocks I pasted it again beneath this message to
you.

That do loop you should never use anymore in my opinion.

If you want to use it you can add something as
\\\
do while xx
threading.thread.sleep(1000) ' this is the main thread which sleeps than 1
second,
...........
loop
///
But I think you can better use a timer as I show bellow.

Maybe this helps you?

Cor

\\\form1
Private frm As New Form2
Private Sub Form1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
frm.Show()
End Sub
///
\\\form2

Private WithEvents timer1 As New Windows.Forms.Timer
Private Sub Form2_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "High I Am Here"
Me.ForeColor = Color.White
timer1.Enabled = True
timer1.Interval = 125
Me.BackColor = Color.CornflowerBlue
Me.Opacity = 1
Me.TopMost = True
Me.Text = "Splash"
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles timer1.Tick
Me.Opacity -= 0.01
If Me.Opacity = 0 Then
timer1.Enabled = False
Me.Close()
End If
End Sub
///
I hope this helps a little bit?

Cor
 
H

Herfried K. Wagner [MVP]

* Scott H said:
Coming from VB6, there was a bit of a difference in the way you
display a form, I Thought I'd nailed instanciating a form, but I'm
quite stuck with something that doesn't make sense.

my main form has an event handler that instanciates a small popup form
each time it fires, the code inside the handler is:

Dim f As New frmInfoPopup
f.Show()

as soon as the End Sub of the handler is reached, it locks that form,
and doesn't repaint it, if I attempt to close it, it says its not
responding, at some point I got some mention of a
"WindowsFormParkingWindow" which wouldn't close.

<http://groups.google.com/groups?ie=UTF-8&q=windowsformsparkingwindow+group:*dotnet*>
 
S

Scott H

Thanks for the code, it did help a little, although i did still get
locks ups, but its fine if I only have one instance, so I've done it a
slightly different way, now things are working well.

The thing is, theres one thing that still puzzles me...this :

private sub example()
dim frm as new Form2
frm.show
end sub

as the frm object is created within the "example" sub, when it hits
the end sub line, how come the "frm" object isn't distroyed....its
gone out of scope hasn't it?

The reason I ask is, it seemed like this is what was happening in my
app, as soon as it hit the end sub it was trying to both open and
close the form just created...maybe I'm wrong.

Thanks,
Scott

Maybe this helps you?
\\\form1
Private frm As New Form2
<SNIP>
 
C

Cor

Hi Scott,

Thanks for the code, it did help a little, although i did still get
locks ups, but its fine if I only have one instance, so I've done it a
slightly different way, now things are working well.

The thing is, theres one thing that still puzzles me...this :

private sub example()
dim frm as new Form2
frm.show
end sub

That sample is exacly about the problem you describe, why did you not try
it?
(You can replace that private form to that as you have above)

Cor
 
H

Herfried K. Wagner [MVP]

* Scott H said:
The thing is, theres one thing that still puzzles me...this :

private sub example()
dim frm as new Form2
frm.show
end sub

as the frm object is created within the "example" sub, when it hits
the end sub line, how come the "frm" object isn't distroyed....its
gone out of scope hasn't it?

The reason I ask is, it seemed like this is what was happening in my
app, as soon as it hit the end sub it was trying to both open and
close the form just created...maybe I'm wrong.

The form won't be closed then 'frm' runs out of scope.
 

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