C#通过按钮单击切换面板

时间:2018-02-10 01:27:51

标签: c# panels

我无法切换已经在面板内部的面板。我正在尝试使用Switchable选项卡创建一个Windows窗体,我希望面板根据用户单击的按钮进行切换。我试着像这样编码

private void Dashboard_Click(object sender, EventArgs e)
{
    pnl_dashboard.Visible = true;
    pnl_purchase_sales.Visible = false;
    pnl_order_stocks.Visible = false;
    pnl_inventory_forecasting.Visible = false;
    pnl_stocks.Visible = false;
    pnl_alert_logs.Visible = false;
    pnl_accounting_tools.Visible = false;
}

private void Purchase_sales_Click(object sender, EventArgs e)
{
    pnl_purchase_sales.Visible = true;
    pnl_purchase_sales.BringToFront();
    pnl_order_stocks.Visible = false;
    pnl_inventory_forecasting.Visible = false;
    pnl_stocks.Visible = false;
    pnl_alert_logs.Visible = false;
    pnl_accounting_tools.Visible = false;
}

private void stocks_Click(object sender, EventArgs e)
{
    pnl_stocks.Visible = true;
    pnl_stocks.BringToFront();
    pnl_purchase_sales.Visible = false;
    pnl_order_stocks.Visible = false;
    pnl_inventory_forecasting.Visible = false;
    pnl_alert_logs.Visible = false;
    pnl_accounting_tools.Visible = false;
}

private void order_stocks_Click(object sender, EventArgs e)
{
    pnl_order_stocks.Visible = true;
    pnl_order_stocks.BringToFront();
    pnl_purchase_sales.Visible = false;
    pnl_inventory_forecasting.Visible = false;
    pnl_stocks.Visible = false;
    pnl_alert_logs.Visible = false;
    pnl_accounting_tools.Visible = false;
}

private void inventory_forecasting_Click(object sender, EventArgs e)
{
    pnl_inventory_forecasting.Visible = true;
    pnl_inventory_forecasting.BringToFront();
    pnl_purchase_sales.Visible = false;
    pnl_order_stocks.Visible = false;
    pnl_stocks.Visible = false;
    pnl_alert_logs.Visible = false;
    pnl_accounting_tools.Visible = false;
}

private void alert_logs_Click(object sender, EventArgs e)
{
    pnl_alert_logs.Visible = true;
    pnl_alert_logs.BringToFront();
    pnl_purchase_sales.Visible = false;
    pnl_order_stocks.Visible = false;
    pnl_inventory_forecasting.Visible = false;
    pnl_stocks.Visible = false;
    pnl_accounting_tools.Visible = false;
}

private void accounting_tools_Click(object sender, EventArgs e)
{
    pnl_accounting_tools.Visible = true;
    pnl_accounting_tools.BringToFront();
    pnl_purchase_sales.Visible = false;
    pnl_order_stocks.Visible = false;
    pnl_inventory_forecasting.Visible = false;
    pnl_stocks.Visible = false;
    pnl_alert_logs.Visible = false;
}

当你从主面板开始向下时它起作用但是当你随机点击一个面板时它不会工作。这是我的表格

enter image description here

1 个答案:

答案 0 :(得分:0)

如果没有看到更多代码,很难分辨,但可能是因为pnl_dashboard.Visible永远不会设置为假?