tags:

views:

31

answers:

2

I have a .NET forms application using a tab control with several tabs. There are a few elements (a button and a few text boxes) that need to be displayed on every tab. Rather than create 5 seperate elements (including all the appropriate properties), is there a way to create "links" to one element?

For example, when an event occurs, I need a textbox to display the same information in each tab. As it stands, I need to create a new textbox for each tab, then explicitly write to each. It would be easiest to just write to one textbox, then consider the rest "links" which automatically update.

+1  A: 

Sorry, there isn't any way to do this. controls on a form are childen of that form, they can't be simultaneously children of multiple forms. (a tab is basically a sub-form).

You could either create an array of references to all of the textboxes that you want to behave the same, and and write to all of them when you write to one of them. Or keep the text in some location outside of the textbox, and update the textbox on the visible tab when ever the user changes tabs.

John Knoeller
+2  A: 

Those controls really ought to be somewhere else than on a TabPage. But you can get what you want by implementing the SelectedIndexChanged event and change the Parent of the control. This sample code keeps the text box on the selected tab:

    private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) {
        textBox1.Parent = tabControl1.SelectedTab;
    }
Hans Passant