用户控制连接

本文关键字:连接 控制 用户 | 更新日期: 2023-09-27 17:56:31

我已经创建了具有多个用户控件的自助服务终端系统,需要使用冷饮用户控件中的按钮连接热饮用户控件。

当我使用以下代码时,它会同时显示两个用户控件,并在冷饮下显示热饮。我需要先隐藏冷饮,然后显示热饮。我认为需要在这里使用子和父母连接,但不知道如何做到这一点。请帮助我。

OrderTakingMenu ordertakingmenu;
HotDrinks hotDrinks;
public UserControl currentPanel;
public ColdDrink(OrderTakingMenu ordertakingmenuIn)
{
    InitializeComponent();
    this.Location = new System.Drawing.Point(5, 100);
    ordertakingmenu = ordertakingmenuIn;
}
private void btnHotDrinks_Click(object sender, EventArgs e)
{
    removePreviousPanel();
    currentPanel = new HotDrinks(ordertakingmenu);
    this.Controls.Add(currentPanel);
}
private void removePreviousPanel()
{
    this.Controls.Remove(currentPanel);
}

用户控制连接

我会使用Visible属性。 首先在窗体上添加两个用户控件,并使它们相互重叠(两者位于同一位置,大小相同)。

public ColdDrink(OrderTakingMenu ordertakingmenuIn)
{
    InitializeComponent();
    this.Location = new System.Drawing.Point(5, 100);
    ordertakingmenu = ordertakingmenuIn;
    coldDrinksPanel.Visible = true;
    hotDrinksPanel.Visible = false;
}
private void btnHotDrinks_Click(object sender, EventArgs e)
{
    hotDrinksPanel.Visible = true;
    coldDrinksPanel.Visible = false;
}