|
-
Apr 19th, 2009, 08:57 AM
#1
Thread Starter
Junior Member
Associate TextBox with Tab?
Hello,
I am making a program with tabs, and in each tab is a textbox for editing a file (like how VB's designer does). How can I match up a textbox with a tab so that the cut, copy, paste, select all, etc. in the menu can tell what textbox to preform actions on? I was thinking of getting the current selected tab, and somehow finding the textbox associated with that tab.
Right now I dynamically create a new textbox when a new tab is opened.
Any ideas? Thanks in advance.
-Nick
-
Apr 19th, 2009, 09:18 AM
#2
Re: Associate TextBox with Tab?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 19th, 2009, 10:11 AM
#3
Thread Starter
Junior Member
Re: Associate TextBox with Tab?
Hmm that didn't work. My controls are inside of a SplitContainer and it selects that instead of the textbox.
-
Apr 19th, 2009, 10:16 AM
#4
Re: Associate TextBox with Tab?
try this:
vb Code:
DirectCast(Me.SplitContainer1.ActiveControl, TextBox).Paste()
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 19th, 2009, 10:19 AM
#5
Re: Associate TextBox with Tab?
if you have other controls in your splitcontainer that aren't textboxes, you'll need to test if its the textbox that has the focus:
vb Code:
if typeof Me.SplitContainer1.ActiveControl is textbox then
'your code
end if
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 19th, 2009, 10:22 AM
#6
Thread Starter
Junior Member
Re: Associate TextBox with Tab?
Wow, that worked, thanks!
-
Apr 19th, 2009, 10:35 AM
#7
Thread Starter
Junior Member
Re: Associate TextBox with Tab?
Well, what if the textbox inside that tab isn't the active control? I still need to find out what textbox is inside the selected tab.
When I create the tabs, the Name property on the created textbox is set to PathToFile + "Box" so I can predict what the name of the textbox is, but I can't use it to select the textbox in my code (it formats it as a string, not a control). Any way around this?
-
Apr 19th, 2009, 10:41 AM
#8
Re: Associate TextBox with Tab?
to refer to the textbox in code:
vb Code:
directcast(me.controls(PathToFile & "Box"), textbox)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 19th, 2009, 10:42 AM
#9
Thread Starter
Junior Member
Re: Associate TextBox with Tab?
-
Apr 19th, 2009, 10:43 AM
#10
Re: Associate TextBox with Tab?
you might need to use:
vb Code:
me.SplitContainer1.controls
instead of:
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 19th, 2009, 10:50 AM
#11
Thread Starter
Junior Member
Re: Associate TextBox with Tab?
EH. I tried to run the following:
vb Code:
MsgBox(DirectCast(Me.Controls(projectPath & "\" & Me.TabControl1.SelectedTab.Text & "Box"), RichTextBox).Text)
..and got a NullReferenceException.
Why?
EDIT: Lol, didn't see your previous post, I'll try that.
-
Apr 19th, 2009, 10:52 AM
#12
Thread Starter
Junior Member
Re: Associate TextBox with Tab?
Yeah, Me.SplitContainer1.Controls didn't work either. NullReferenceException.
-
Apr 19th, 2009, 10:53 AM
#13
Re: Associate TextBox with Tab?
whats the exact name of the textbox?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 19th, 2009, 10:57 AM
#14
Thread Starter
Junior Member
Re: Associate TextBox with Tab?
Let me explain how it works.
When you open a project, it lists the directory structure of the project to the left of the tabs in a TreeView. When you double-click a file in the TreeView, it opens a new tab in TabControl1 and dynamically creates a textbox in the new tab (and loads in the file's contents). The textbox's Name property is set to the following:
vb Code:
textbox.Name = projectPath + "\" + TreeView1.SelectedNode.Text + "Box"
The projectPath is not null, because it is set when a project is opened. As you can see, it gets the project path and adds the selected node in the TreeView's text, and finally adds on "Box" to the end. The Name property ends up looking like this:
C:\MyApp\Projects\MyProject\File.txtBox
I use the full path, and not just the filename, in case there are multiple files with the same name (in different folders).
-
Apr 19th, 2009, 11:08 AM
#15
Re: Associate TextBox with Tab?
i experimented with it. this works:
vb Code:
Dim tb As New TextBox
tb.Name = "C:\MyApp\Projects\MyProject\File.txtBox"
tb.Text = "test"
Me.SplitContainer1.Panel1.Controls.Add(tb)
MsgBox(DirectCast(Me.SplitContainer1.Panel1.Controls("C:\MyApp\Projects\MyProject\File.txtBox"), TextBox).Text)
if something similar to this doesn't work for you, you must have the textbox name wrong
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 19th, 2009, 11:16 AM
#16
Thread Starter
Junior Member
Re: Associate TextBox with Tab?
OH!
I had it set wrong:
vb Code:
DirectCast(Me.SplitContainer1.Controls(projectPath & "\" & Me.TabControl1.SelectedTab.Text & "Box"), RichTextBox).Text
When in reality, I make the controls under TabControl1, inside of a TabPage, so this would work:
vb Code:
DirectCast(Me.TabControl1.TabPages.Item(Me.TabControl1.SelectedTab.Text).Controls(projectPath & "\" & Me.TabControl1.SelectedTab.Text & "Box"), RichTextBox).Text
...and it did.
Thanks for all the help, paul, really appreciate it.
Tags for this Thread
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
|