[RESOLVED] MDI childforms probleem.
Hi all,
I want to create an arraylist from MDI childforms and I did it like this:
vb.net Code:
Dim sl As New SortedList(Of Integer, Form)
Dim i As Integer
Dim form As Form
For Each form In Me.MdiChildren
sl.Add(CInt(form.Text), form)
Next
form = New Form
form.MdiParent = Me
If sl.Count > 0 Then
For i = 1 To Integer.MaxValue
If sl.Keys.IndexOf(i) = -1 Then Exit For
Next
form.Text = i.ToString
Else
form.Text = "1"
End If
form.Show()
It's working great, that means that if I delete a childform for example number 2 from all 3 then it creats first number 2 again and then number 4.
Now the problem is that It only shows the childformnumber in the parentformtext instead of the name and number of that childform,like this: parentform - childform 1
Re: MDI childforms probleem.
I don't know if i understand, but you're saying that when you have your form maximized and the mdi children maximized to, you only see FORMPARENTTEXT - NUMBER, instead of FORMPARENTTEXT - CHILDFORM - NUMBER?
I think that's the normal behavior, you set the text of your child form's like this, , so the name will be (1,2,3), then it's normal that you only see the number, nothing more...
Re: MDI childforms probleem.
i don't test it but i think because
i.tostring is the form number
so
Code:
form.Text = i.ToString
is returning only numbers
i didn't test so i guess this is
sorry if i was wrong or if i missed understand you
Re: MDI childforms probleem.
sorry mickey i didn't see your post
:):)
Re: MDI childforms probleem.
Hi,
Yes you're right that gives me only numbers, but when I use thei;
vb Code:
form.Text = "Childform" & " " & i.ToString
Then it gives me an error.
the convertion from Child 2 to type Long is invalid.
Re: MDI childforms probleem.
That error occurs when you are adding the items to the list...
Try to replace by this:
VB.NET Code:
sl.Add(CInt(Form.Text.Substring(Form.Text.IndexOf(" ") + 1)), Form)
That's because your sorted list it's of integers...
Re: MDI childforms probleem.
Hi mickey,
It's nearly working, the only problem is that it gives me only the number for the first childform and not the childform - number, but from the second childform it gives me the proper text.
Re: MDI childforms probleem.
You must set to the first one to....
VB.NET Code:
form.Text = "Childform 1"
Re: MDI childforms probleem.
Hi Mickey,
Thanks, it's working now.
Here's the whole code:
vb Code:
Dim sl As New SortedList(Of Integer, Form)
Dim i As Integer
Dim form As child
For Each form In Me.MdiChildren
sl.Add(CInt(form.Text.Substring(form.Text.IndexOf(" ") + 1)), form)
Next
form = New Child
form.MdiParent = Me
If sl.Count > 0 Then
For i = 1 To Integer.MaxValue
If sl.Keys.IndexOf(i) = -1 Then Exit For
Next
form.Text = "Child" & " " & i.ToString
Else
form.Text = "Child 1"
End If
form.Show()