Home All Groups Group Topic Archive Search About

Strange behavior when Removing a TabPage

Author
9 Aug 2006 5:40 PM
erikssonjimmie@hotmail.com
ref class TabPageInfo
{
public:
    System::Drawing::Size        m_orgSize;
    System::Drawing::Point        m_orgLocation;
    String^                m_name;
    System::Windows::Forms::TabPage^    m_tabPage;
};

System::Collections::Generic::List<TabPageInfo^> m_tabPageInfos;

private: System::Void addTab(String ^ pageName) {
    TabPageInfo^ tabPageInfo = gcnew TabPageInfo();
    System::Windows::Forms::TabPage^ tabPage = gcnew
System::Windows::Forms::TabPage();
    tabPageInfo->m_orgLocation = System::Drawing::Point(4, 22);
    tabPageInfo->m_orgSize = System::Drawing::Size(612, 574);
    tabPageInfo->m_name = pageName;
    tabPage->Location = tabPageInfo->m_orgLocation;
    tabPage->Size = tabPageInfo->m_orgSize;
    tabPage->Name = pageName;
    tabPage->Padding = System::Windows::Forms::Padding(3);
    tabPage->TabIndex = m_adPageInfo.Count;
    tabPage->Text = pageName;
    tabPage->UseVisualStyleBackColor = true;
    tabPageInfo->m_tabPage = tabPage;
    m_tabPageInfos.Add(tabPageInfo);
    this->tabControl1->Controls->Add(tabPage);
    m_adPageInfo.Add(gcnew array<AdInfo^>(adCount));
    for (int i = 0; i < adCount; ++i) {
        m_adPageInfo[tabPage->TabIndex][i] = gcnew AdInfo();
    }
}

private: System::Void removeCurrentTab() {
    if (m_tabPageInfos.Count <= 1)
        return;

    // Remove all images filename
    m_adPageInfo.RemoveAt(m_tabIndex);

    // Remove the tabcontrol
    System::Windows::Forms::TabPage^% tabPage =
m_tabPageInfos[m_tabIndex]->m_tabPage;

// Here comes the strange behavior...
    this->tabControl1->Controls->Remove(tabPage);// this line decrements
m_tabIndex by one ?!!?!?!?? shall it do that? how could that be???
// so when I continue here it doesn't do what I think it should do... any
explanation on this behavior would be what I'm looking for...

    m_tabPageInfos.RemoveAt(m_tabIndex);
    --m_tabIndex;
    showAdPage(m_tabIndex);
}

AddThis Social Bookmark Button