C++/CLI Winforms ToolStripMenuItem Checked property

419 Views Asked by At

I develop a Winforms app in C++/CLI. I added a MenuStrip object to my MDI Parent form. In the MenuStrip is a ToolStripMenuItem object, and to its DropDownItems collection is added a ToolStripMenuItem object everytime a new MDI Child form is created. I want to set the Checked property of a ToolStripMenuItem to true everytime it is clicked (and set it to false for all other ToolStripMenuItem instances). But there seems to be a problem displaying the check mark :

Check mark does not display, instead a blue rectangle is displayed

In the picture, the fourth item is supposed to be checked, but instead of displaying the check mark, all I see is a blue rectangle.

Here is the function in the MDI Parent form that creates a new canvas object (derived from System::Windows::Forms::Form class) :

void AddAndShowCanvas(ProjectID type, unsigned int index, System::String^ name, bool demo, bool data) {
    m_Canvases->push_back(gcnew canvas(m_MainController, this, type, index, name, demo, data));
    m_Canvases->back()->MdiParent = this;
    m_menuStrip->AddCanvasToWindowsToolStrip(m_Canvases->back());

    if (data)
        m_Canvases->back()->GetMainPanel()->DisplayLoadedFile();

    m_Canvases->back()->Show();
}

Here is the function in hydro_menustrip class (derived from System::Windows::Forms::MenuStrip class) that adds a ToolStripMenuItem to a ToolStripMenuItem (declared as m_windowsToolStripMenuItem) of the hydro_menustrip instance :

void hydro_menustrip::AddCanvasToWindowsToolStrip(canvas^ canvas) {
    System::Windows::Forms::ToolStripMenuItem^ canvasItem = 
        gcnew System::Windows::Forms::ToolStripMenuItem(canvas->GetProjectTitle());
    m_windowsToolStripMenuItem->DropDownItems->Add(canvasItem);
    m_windowsToolStripMenuItem->DropDownItems[m_windowsToolStripMenuItem->DropDownItems->Count - 1]->PerformClick();
    canvasItem->Click += canvas->OpenCanvasEvent;
}

And here is the DropDownItemClicked event added to the m_windowsToolStripMenuItem object :

void hydro_menustrip::windows_DropDownItemClicked(System::Object^ sender, ToolStripItemClickedEventArgs^ e) {
    for each(ToolStripMenuItem^ item in m_windowsToolStripMenuItem->DropDownItems)
        item->Checked = false;

    safe_cast<ToolStripMenuItem^>(e->ClickedItem)->Checked = true;
}
0

There are 0 best solutions below