Problem:Tabpage image addition via Imagelist in code

Mindrage

Member
Joined
Apr 10, 2010
Messages
5
Programming Experience
1-3
Hi guys, I got some problems ,

first it adds a tabpage to a tabcontroll.
Then its supposed to add the assigned "form" that is connected to the tab page.
(When i click the tab page the window gets focused).
But when i try to add a image to the imagelist and assign the imagelist index to the tab page. It doesnt show up.


VB.NET:
'additional code understanding
    Public CurrentKey As Integer
    Public ChildForms(511) As Form
    Public ChildFormKeys(511) As String

  Public Function RegisterForm(ByVal addedform As Form)
        For Each f As Form In Me.MdiChildren
            If f.Name = addedform.Name Then
                Me.FormTab.TabPages.Add(addedform.Name, f.Text)
                Me.TabImages.Images.Add(addedform.Name, Me.MenuStrip.BackgroundImage)
                Me.FormTab.TabPages(Me.FormTab.TabPages.IndexOfKey(addedform.Name)).ImageKey = Me.TabImages.Images.IndexOfKey(addedform.Name)
                ChildForms(GetFormIndex(addedform.Name)) = addedform
                ChildFormKeys(CurrentKey) = addedform.Name
                CurrentKey = CurrentKey + 1
            End If
        Next f
    End Function

'GetFormIndex just located the index of the Tag from the "Name" of the form


Well, As i add and bind the images it doesnt show up.

So anyone..?
 
refactored I get this code, then I assigned the ImageKey the key (where you had index)
VB.NET:
Public Sub RegisterForm(ByVal addedform As Form)
    Me.TabImages.Images.Add(addedform.Name, Me.MenuStrip.BackgroundImage)
    Dim page As New TabPage(addedform.Text)
    page.Name = addedform.Name
    page.ImageKey = addedform.Name
    Me.FormTab.TabPages.Add(page)

End Sub
What is the purpose of your ChildForms/ChildFormsKeys arrays? I don't think you need them. When you need to find the corresponding form for a tabpage you could simply map the form reference to the page.Tag. Since I don't know the purpose there could be other easier solutions also.
 
Well its a mdi form where you got a tabstrip that sets focus on a form when you click it.
I save all the forms in an array to be able to use the system.
I try to avoid using custom controls so it became in that way.

Anyways, When i add the tabPage, It set the formname as the key to the tabpage but i try also to make the icon of the form as a picture for the tabpage.

So basically its like a Windows "start menu" but only with the MDi childs of the form.

The main idea with my whole project is a online desktop using mySQL.
 
Back
Top