If there is a thread related to this one please reply back the url, thx

What i have is Parent form that is the owner of multiple child forms, im having trouble trying to display the form, it flashes and then disappears


Code:

PrivateSub spawnNewChild(ByVal Name AsString, ByVal IP AsString, ByVal Mess AsString)

Dim ownedForm AsNew frmChild
With ownedForm
.Name = IP
.Text = Name
.txtReceived.AppendText(Mess + vbCrLf)
EndWith

Me.AddOwnedForm(ownedForm)

With ownedForm
.Show()
.txtSend.Focus()
EndWith

EndSub

Any help would be great, thx Jaeman

Hrm.. Looks like your bringing the other form ahead to early.. is that the entire code?

Lets start basic trouble shooting and put msgbox breaks in each line so we cna find out when she disappears.

Example..

msgbox "gothere"
something.sendFocus
msgbox "got here"

You follow?

Good to see im not the only one that uses mboxes for debugging, it should be the first recommendation made before someone posts a thread for the first time, Anyway...

Code has been changed but it should not affect it in anyway, it seems that the form disappears after the instantiation of the child form.

PrivateSub spawnNewChild(ByVal Name AsString, ByVal IP AsString, ByVal Mess AsString)

Dim ownedForm AsNew frmChild(IP,Name)

Me.AddOwnedForm(ownedForm) [No Problem - NP]

With ownedForm
.Show() - [NP]
.txtReceived.AppendText(Mess + vbCrLf) [NP]
.txtSend.Focus() [NP]
EndWith

EndSub


--- In Use - I put in a mBox and the form stays visible untill the messagebox is closed.

spawnNewChild("Jeff","192.168.0.1")
msgbox("Spawned") - [Still Visible]
Msgbox closed [Disappears]

Have you tried renaming this window to something else.. Can you paste full code.. soemthing is missing here..

This should be enough code to understand what i am doing.

When opening[spawning] a new child form the IP for that user is used as the forms Name, Then when a new message arrives it is send to the FindClient Sub to see if the form is open/active or not[and there is no problem with that], but if the form is not active the Sub the askes the user if they would like to accept the message, if they select Yes then the child form is opened/spawned, but you just get a flash of the form before it disappears, Note that once this happens you can't manualy open the form as it is already open, and i've tryed .Show .Visible = true etc etc to make the form visible.

' Open new chat window
Private Sub spawnNewChild(ByVal Name As String, ByVal IP As String, ByVal Mess As String)
Dim child As New frmChild(Name, IP)

frmMain.ActiveForm.AddOwnedForm(child)
With child
.Show()
If Not Equals(Mess, "") Then
.txtReceived.AppendText(Mess + vbCrLf)
End If
.txtSend.Focus()
End With
End Sub

' Find the Client and send message or ask to open new child
Private Sub findClient(ByVal FormName As String, ByVal Message As String)
Dim frm As frmChild
Dim blnFound As Boolean = False

For Each frm In Me.OwnedForms
With frm
' Look for the open form
If Equals(.Name, FormName) Then
.Controls(0).Text = Message ' Control(0) = childs message received box
blnFound = True
Exit Sub
End If
End With
Next

If Not blnFound Then
' Split the name, date from the message
Dim inMSG() As String = Split(Message, " : ")
Dim User() As String = Split(inMSG(0), " : ")
' Ask to accept incoming message
Dim msg As String = _
"Do you want to accept a message from " _
+ inMSG(0) + " ..?"
Dim Result As DialogResult = _
MessageBox.Show(msg, "Incoming Message", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Question)
' Check the result
If Equals(Result, DialogResult.Yes) Then
' New Child
' Check if client is reachable
spawnNewChild(User(0), FormName, Message)
Else
' Message is ignored
End If
End If
End Sub

---

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.