|
-
Jan 25th, 2003, 05:35 PM
#1
Thread Starter
Lively Member
[resolved] Dynamic conrtol creation and Collections
I am having a problem understanding control collections. My application starts with a TabControl and one TabPage. The TabPage contains a RichTextBox
Through a menu option the user may add additional tab pages. When a tab page is created, a RichTExtBox is placed in it by the program. Basically each page is an index card you can write on.
When I create a new tabpage I use the following code:
Private Sub TopicAddMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TopicAddMenuItem.Click
' Create a new tab and add a rich text box to it
' Set up variables to prompt for Tab name
Dim message, title As String
Dim myValue As Object
message = "Enter Tab Name" ' Set prompt.
title = "SmartPad" ' Set title.
' Set up variables for new Tab page and Rich Text Box
Dim TabPageNew As System.Windows.Forms.TabPage
Dim RichTextBoxNew As System.Windows.Forms.RichTextBox
RichTextBoxNew = New System.Windows.Forms.RichTextBox()
RichTextBoxNew.Location = New System.Drawing.Point(8, 48)
RichTextBoxNew.Name = "RichTextBoxNew"
RichTextBoxNew.Size = New System.Drawing.Size(512, 248)
RichTextBoxNew.TabIndex = 0
RichTextBoxNew.Text = ""
'TabPageNew
'
TabPageNew = New System.Windows.Forms.TabPage()
TabPageNew.Controls.AddRange(New System.Windows.Forms.Control() {RichTextBoxNew})
TabPageNew.Location = New System.Drawing.Point(4, 22)
TabPageNew.Name = "TabPageNew"
TabPageNew.Size = New System.Drawing.Size(528, 302)
TabPageNew.TabIndex = 0
' Display message, title and get the Tab Name
Do
myValue = InputBox(message, title)
Loop Until myValue <> ""
TabPageNew.Text = myValue
' add the control, make the new tab active and bring focus to the rich text box
Me.SmartPadTabControl.Controls.AddRange(New System.Windows.Forms.Control() {TabPageNew})
Me.SmartPadTabControl.SelectedIndex = Me.SmartPadTabControl.TabCount - 1
RichTextBoxNew.Focus()
End Sub
My problem is figuring out how to access the rich text box on any given page.
For example, suppose the user creates five tabs and they each have a richtext box. If the user changes from one page to the next, I want focus to go to the richtextbox on THAT page. How do I do this?
Me.ActiveControl returns the TabControl when you change tab pages, so I have no problem finding which tab page I am now on, but I can't figure out how to get to the rtbox.
Thanks!
Last edited by ggprogram; Jan 26th, 2003 at 01:43 PM.
-
Jan 26th, 2003, 01:42 PM
#2
Thread Starter
Lively Member
Solved
Finally figured it out. You have to find the current TabPage from the TabControl.SelectedIndex and then cycle through all the objects on the page to find the rich text box.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|