I have discovered a nasty tabcontrol bug. Or it could be just me.
Test case is simple. Create a tabcontrol with 5 tabs. Add event handler on selectedIndex change and print out the tab order. The tab order will magically change only if you click on tab page 5 then tab page 3. The indexes in the tab control gets shuffled. The tab page indexed by the selectedIndex isn't what you expect it to be. The SelectedTab property yields the correct tab however.
#pragma once
namespace testform
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
stringarray = new ArrayList();
stringarray->Add(S"0");
stringarray->Add(S"1");
stringarray->Add(S"2");
stringarray->Add(S"3");
stringarray->Add(S"4");
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
ArrayList * stringarray;
private: System::Windows::Forms::TabControl * tabControl1;
private: System::Windows::Forms::TabPage * tabPage1;
private: System::Windows::Forms::TabPage * tabPage2;
private: System::Windows::Forms::TabPage * tabPage3;
private: System::Windows::Forms::TabPage * tabPage4;
private: System::Windows::Forms::TabPage * tabPage5;
private: System::ComponentModel::IContainer * components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->tabControl1 = new System::Windows::Forms::TabControl();
this->tabPage1 = new System::Windows::Forms::TabPage();
this->tabPage2 = new System::Windows::Forms::TabPage();
this->tabPage3 = new System::Windows::Forms::TabPage();
this->tabPage4 = new System::Windows::Forms::TabPage();
this->tabPage5 = new System::Windows::Forms::TabPage();
this->tabControl1->SuspendLayout();
this->SuspendLayout();
//
// tabControl1
//
this->tabControl1->Controls->Add(this->tabPage1);
this->tabControl1->Controls->Add(this->tabPage2);
this->tabControl1->Controls->Add(this->tabPage3);
this->tabControl1->Controls->Add(this->tabPage4);
this->tabControl1->Controls->Add(this->tabPage5);
this->tabControl1->Dock = System::Windows::Forms::DockStyle::Fill;
this->tabControl1->Location = System::Drawing::Point(0, 0);
this->tabControl1->Name = S"tabControl1";
this->tabControl1->SelectedIndex = 0;
this->tabControl1->Size = System::Drawing::Size(704, 470);
this->tabControl1->TabIndex = 0;
this->tabControl1->SelectedIndexChanged += new System::EventHandler(this, _SelectedIndexChanged);
//
// tabPage1
//
this->tabPage1->Location = System::Drawing::Point(4, 22);
this->tabPage1->Name = S"tabPage1";
this->tabPage1->Size = System::Drawing::Size(696, 444);
this->tabPage1->TabIndex = 0;
this->tabPage1->Text = S"tabPage1";
//
// tabPage2
//
this->tabPage2->Location = System::Drawing::Point(4, 22);
this->tabPage2->Name = S"tabPage2";
this->tabPage2->Size = System::Drawing::Size(192, 74);
this->tabPage2->TabIndex = 1;
this->tabPage2->Text = S"tabPage2";
//
// tabPage3
//
this->tabPage3->Location = System::Drawing::Point(4, 22);
this->tabPage3->Name = S"tabPage3";
this->tabPage3->Size = System::Drawing::Size(192, 74);
this->tabPage3->TabIndex = 2;
this->tabPage3->Text = S"tabPage3";
//
// tabPage4
//
this->tabPage4->Location = System::Drawing::Point(4, 22);
this->tabPage4->Name = S"tabPage4";
this->tabPage4->Size = System::Drawing::Size(192, 74);
this->tabPage4->TabIndex = 3;
this->tabPage4->Text = S"tabPage4";
//
// tabPage5
//
this->tabPage5->Location = System::Drawing::Point(4, 22);
this->tabPage5->Name = S"tabPage5";
this->tabPage5->Size = System::Drawing::Size(192, 74);
this->tabPage5->TabIndex = 4;
this->tabPage5->Text = S"tabPage5";
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(704, 470);
this->Controls->Add(this->tabControl1);
this->Name = S"Form1";
this->Text = S"Form1";
this->tabControl1->ResumeLayout(false);
this->ResumeLayout(false);
}
void _SelectedIndexChanged(System::Object * sender, System::EventArgs * e)
{
String * pOrder2 = S"";
IEnumerator * pEnum = this->tabControl1->Controls->GetEnumerator();
while (pEnum->MoveNext())
pOrder2 = String::Concat(pOrder2,S" ",(static_cast <TabPage *> (pEnum->Current)->Text));
MessageBox::Show(pOrder2);
}
};
}