prevent System.Windows.Forms.TabControl.ControlCollection to change SelectedIndex at Remove method
-
Hello everybody! I'm working on an application which has UserControls (GUI pages) with TabControls on it. This TabControls are Usercontrols derived from Windows.Forms.TabControl. Same to TabPage. The TabPage class has a "Visible" property which removes the TabPage from TabControl.TapPages property, if it's set to false. This Visible property is refreshed over an userdefined binding mechanism. This means if I change my page, the Visible property of the TabPages will be refreshed. On default the SelectedIndex property of the TabControl is set to "0". Now what's my problem: I allways had strange visual effects as the TabPages where removed from the Collection. I saw the different TabPages flickering until all the TabPages where removed. Thank's to Lutz Roeder's reflector I found out that the framework is forcing the SelectedIndex property after removing the tabpage.
public override void Remove(Control value)
{
base.Remove(value);
if (value is TabPage)
{
int index = this.owner.FindTabPage((TabPage) value);
if (index != -1)
{
this.owner.RemoveTabPage(index);
this.owner.SelectedIndex = Math.Max(index - 1, 0);
}
this.owner.UpdateTabSelection(false);
}
}I now whant to find a solution which prevents the SelectedIndex property to change when removing a TabPage. What I was thinking of: As the SelectedIndex property is not virtual I'm not able to override it in my TabControl class. Maybe I could inherit a TabPageCollection class, for my TabPages property of TabControl class, which overrides the "Remove" method. And after that ???? Thanks for your time. All the best, Martin