My first vb.net post...:)
What I've got:
On a form, I have 'Add New Tab' button, a 'Select Picture' button and a TabControl.
On the first Tab I have a textbox1and a picturebox1, when the user uses the 'Select picture' button (which calls opentdialog) I load the picture into the picture box and put the selected filename into the text box. - so far so good.
However, I want the user to be able to add as many Pictures as they want so what I've done is:
I dynamically add a new tab every time the user presses the 'Add new Tab', and dynamically create new text box and picture box on each new tab. I call (name) them by the number of total tabs I have, so the textbox and picturebox on tab2 will be: textbox2 and a picturebox2 , the textbox and picturebox on tab3 will be: textbox3 and a picturebox3 etc.
When I get the selected filename , I wish to populate the textbox dependent upon which tab is currently selected.
So how to I refer to the control (in this case my textbox) by name.
My 'new' button does this:
CreateNewImageTab(tcImages.TabCount + 1) Here's my routine where I create the new tab, picturebox:
Sub CreateNewImageTab(ByVal iImage As Integer) Dim sImageId As String Dim sImageN As String Dim sNewtabName As String 'New Image Id sImageId = CStr(iImage) sImageN = "Image" & sImageId ' New tab Dim newtabpage As New TabPage sNewtabName = "tab" & sImageN ' New Picture box Dim ImagePicturebox As New PictureBox Dim sNewImageboxName As String = "pb" & sImageN ' ' New tab ' frmMain.tcImages.Controls.Add(newtabpage) ' New Picture box newtabpage.Controls.Add(ImagePicturebox) End Sub
My 'Select' button does this: ie gets the selected file name.
If Me.OpenFileDialogImages.ShowDialog() = System.Windows.Forms.DialogResult.OK Then LoadImage(Me.OpenFileDialogImages.FileName) End If
I just want to know how to refere to the objects on the currently selected tab, by name in my loadimage routine
Sub LoadImage(ByVal sFilename As String) Dim iImage As Integer Dim FilenameboxName As String Dim PictureBoxName As String iImage = frmMain.tcImages.SelectedIndex + 1 PictureBoxName = "PbImage" & Cstr(iImage) ??? ??? End Sub
I'm sure it must be simple but I just can't seem to figure it out.
Thanks in advance for any help.