I am trying to build controls on a tab in form1 from a click event on form2. Thanks to some previous help on here I am able to add a label and a texbox. I tried applying the same syntax to adding an image from an imagelist but it will not work. I am stuck on how to proceed.
Here is what I have so far:
Private Sub butAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butAdd.Click
Dim tabAttLbl As New Label
Dim tabAttTxt As New TextBox
Dim tabAttImg As New Image 'New gives an error = New can not be used on a class that is declared 'MustInherit so I removed New
tabAttLbl.Size = New Size(48, 16)
tabAttTxt.Size = New Size(136, 20)
tabAttImg.Size = New Size(16, 16) 'error is read only so I dropped New and still an error says it can not be indexed
tabAttImg = clsGlobals.Form1.ImageList1.Images(0) - The image index I wish to add
tabAttLbl.Location = New Point(8, 8)
tabAttTxt.Location = New Point(64, 8)
tabAttImg.Location = New Point(208,8) 'error Location is not part of the colllection of events
tabAttLbl.Name = txtName.Text
tabAttLbl.Text = txtName.Text
tabAttTxt.Name = txtName.Text
clsGlobals.Form1.TabControl1.SelectedTab.Controls.Add(tabAttLbl) 'this works fine
clsGlobals.Form1.TabControl1.SelectedTab.Controls.Add(tabAttTxt) 'this works fine
clsGlobals.Form1.TabControl1.SelectedTab.Controls.Add(tabAttImg) 'error system drawing image cannot be converted to system windows form control
So although it does not work I think you can see what I am attempting - I want a picture in ImageList1 Index 0 on Form1 to be placed at Location 208, 8 Size 16, 16 on TabControl1 Selected Tab on Form1. All of this is being done from a click event on Form2.
I have more questions and help required on building a click event programatically but I will save that for another question.
Any help is appreciated.