Windows Forms Advice - same controls on different Tabpages

D

davidpryce123

Dear Windows Form Designers

I am developing an application that uses a TabControl with several
Tabpages.

On the different Tabpages I wish to allow users to have the access to
the
same controls for instance a textbox to enter a date and time string
for search.

Firstly is there anyway to display the same textbox on four Tabpages
or do
I need to have four date and time fields? How do you keep the date
and time
textboxes the same across the four Tabpages.

Secondly if you have a combobox that a user selects an account number
from,
how can you adjust each other Tabpage so that the use does not need to
reselect
the account number if they change between Tabpages?

Thanks

David
 
M

Moty Michaely

Dear Windows Form Designers

I am developing an application that uses a TabControl with several
Tabpages.

On the different Tabpages I wish to allow users to have the access to
the
same controls for instance a textbox to enter a date and time string
for search.

Firstly is there anyway to display the same textbox on four Tabpages
or do
I need to have four date and time fields? How do you keep the date
and time
textboxes the same across the four Tabpages.

Secondly if you have a combobox that a user selects an account number
from,
how can you adjust each other Tabpage so that the use does not need to
reselect
the account number if they change between Tabpages?

Thanks

David

Dear David.
You can set the Container property of the textbox each time the tab
page selection changes like this: textBox1.Container = tabPage1;

On any container change, make sure the layout is proper for your
needs.

Can you be more specific on the second question?

Hope this helps.

Cheers,
Moty.
 
B

Brian Schwartz

For the combobox, try making it a child of the form rather than a child of
each tab page. Position it so that it is on top of the tab pages, and of
course make sure that it is on top of the z-order. This way it will appear
to be on each tab, but there will really only be one, and you won't have
several between which to keep values synchronized.
 
D

davidpryce123

Hi Moty,

I have tried setting the textBox1.Container = tabPage1.

However, I am getting the complie error that

textBox1.Container = tabPage1;

Property or indexer 'System.ComponentModel.Component.Container' cannot
be assigned to -- it is read only.

Am I missing something there?

Thanks

David
 
D

davidpryce123

Here is the actual code I tried.

private void tabControl1_Selecting(object sender,
TabControlCancelEventArgs e)
{
TabControl senderTabControl = (TabControl)sender;
if (senderTabControl.SelectedTab == tabPage1)
{
MessageBox.Show("tabpage 1");
this.textBox1.Container = textBox1;
}
else
{
MessageBox.Show("tabpage 2");
}
}
 
M

Moty Michaely

Here is the actual code I tried.

private void tabControl1_Selecting(object sender,
TabControlCancelEventArgs e)
{
TabControl senderTabControl = (TabControl)sender;
if (senderTabControl.SelectedTab == tabPage1)
{
MessageBox.Show("tabpage 1");
this.textBox1.Container = textBox1;
}
else
{
MessageBox.Show("tabpage 2");
}
}

Hi David,

this code will do the work (inside the SelectedIndexChanged event of
the TabControl control):

if (sender is TabControl)
{
TabControl tc = (TabControl)sender;
tc.SelectedTab.Controls.Add(textBox1);
}

The second line of the if statment will make sure the text box is
assigned to one ControlCollection.

Quote: "A Control can only be assigned to one
Control.ControlCollection at a time. If the Control is already a child
of another control it is removed from that control before it is added
to another control."

Sorry for misleading you with the Container propety.

Have a great week,
Moty
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top