Monday, March 19, 2012

.NET: Displaying the same controls in different tabs on a windows forms application

I was using a tab control in my application, i had some controls in one tab that are common, and should be displayed in all tabs

I did the following to display these controls in all tabs

first I grouped these controls in a GroupBox control, named it for example CommonControldGroupBox

Then in my TabControl, I set the SelectedIndexChanged event to specific function

In this function I added some code to change the parent control of my CommonControldGroupBox control

CommonControldGroupBox .Parent = tabcontrol.TabPages[((TabControl)sender).SelectedIndex];

After running, when I change the tabs, the GroupBox control appears on the same location in all my tabs