Thursday, April 14, 2022

18-Menu Expander Code

 In this post, we will add the code to expand and hide the submenus.

Circuit Submenu Expander

Set the Visible property of the panelCircuitSubmenu to False.

If you run the program now, panelCircuitSubmenu is hidden and the Wire Mode button is now shown below the Circuit button.

To expand the Circuit Submenu panel, add the following code to the Circuit button click event to toggle the panel visibility property.

private void btnCircuit_Click(object sender, EventArgs e)
{
    panelCircuitSubmenu.Visible = !panelCircuitSubmenu.Visible;
}

If you run the program now, the circuit submenu can be expanded and hidden using the Circuit button.

Component Drop Down Menus

Set the Visible property of panelLumpedSubmenu, panelIdealSubmenu, and panelMicrostripSubmenu to False.

If you run the program now, the three component submenus are hidden.

To expand the Lumped Submenu panel, add the following code to the Lumped button click event.

private void btnLumped_Click(object sender, EventArgs e)
{
    panelLumpedSubmenu.Visible = !panelLumpedSubmenu.Visible;
}

If you run the program now, the lumped submenu panel can be shown and hidden with the Lumped button.

Add click handlers for the Ideal button and the Microstrip button to show and hide the ideal submenu and microstrip submenu.

Running the program now, you can show and hide all of the component submenus. Usually, a single drop down menu is displayed at any given time. We will add a helper method that will close the other menus when a new menu is open and provide a capability to close all menus. Add the following method to MainForm.cs

private void closeOtherPanels(Panel thisPanel)
{
    if (thisPanel == panelLumpedSubmenu)
    {
        panelIdealSubmenu.Visible = false;
        panelMicrostripSubmenu.Visible = false;
    }
 
    if (thisPanel == panelIdealSubmenu)
    {
        panelLumpedSubmenu.Visible = false;
        panelMicrostripSubmenu.Visible = false;
    }
 
    if (thisPanel == panelMicrostripSubmenu)
    {
        panelLumpedSubmenu.Visible = false;
        panelIdealSubmenu.Visible = false;
    }
 
    if (thisPanel == null)
    {
        panelLumpedSubmenu.Visible = false;
        panelIdealSubmenu.Visible = false;
        panelMicrostripSubmenu.Visible = false;
    }
}

This method checks accepts the current panel that is to be opened and hides the other two panels. If the current panel is null then all 3 panels are hidden. We will use the null mode in the Mouse Event Handlers.

To enable this capability add a call to each of the 3 submenu click events after making the submenu visible. Pass the current submenu panel to the method.

private void btnLumped_Click(object sender, EventArgs e)
{
    panelLumpedSubmenu.Visible = !panelLumpedSubmenu.Visible;
    closeOtherPanels(panelLumpedSubmenu);
}
 
private void btnIdeal_Click(object sender, EventArgs e)
{
    panelIdealSubmenu.Visible = !panelIdealSubmenu.Visible;
    closeOtherPanels(panelIdealSubmenu);
}
 
private void btnMicrostrip_Click(object sender, EventArgs e)
{
    panelMicrostripSubmenu.Visible = !panelMicrostripSubmenu.Visible;
    closeOtherPanels(panelMicrostripSubmenu);
}

This creates a nice custom drop down menu system by controlling the visibility of panels. The source code for this post is available on GitHub.



No comments:

Post a Comment

34-Microwave Tools with Analysis (Series Final Post)

In this final blog post, I have integrated Y-Matrix analysis into the Microwave Tools project. This version has addition Lumped, Ideal, Micr...