Search code examples
c#winformsc++-cli

C++-CLI Button Arrays to C# Button Arrays in Winforms


I am designing an application in C# Winforms (for the first time). I've designed several applications in C++ in the past, and am having difficulty converting some of my C++-CLI functions to C#.

I have 5 buttons along a side bar that toggles the visibility of the button's corresponding panel per button click. In order to do this, I set the visibility of all other panels to false. In order to achieve this in C++-CLI, I've done the following:

private: System::Void panels_Click(System::Object^  sender, System::EventArgs^  e) {
    System::Windows::Forms::Button ^ currentbutton = (System::Windows::Forms::Button ^) sender;
    array < Panel ^ > ^ objects = { panel1, panel2, panel3, panel4, panel5, panel6};
    array < Button ^ > ^ buttons = { button1, button2, button3, button4, button5, button6 };

    for (int i = 0; i < 6; i++) {
        if (buttons[i]->Equals(currentbutton)) {
            objects[i]->Visible = true;
        }
        else objects[i]->Visible = false;
    }
}

The issue I am having is with the " array Panel ^" portion, as I can not find an equivalent in C#. Any help is appreciated.


Solution

  • Arrays are declared in C# using TypeName[].

    Panel[] objects = { panel1, panel2, panel3, panel4, panel5, panel6 };
    Button[] buttons = { button1, button2, button3, button4, button5, button6 };