带来前端用户控制 - Windows窗体

问题描述 投票:-1回答:1

我有一个名为MovieDetails的用户控件,我将它拖到主窗体但是当我写MovieDetail.BringDetails();时,我收到此错误:

'MovieDetails'不包含'BringTofront'的定义。

如何访问BringToFront方法?

c# winforms
1个回答
0
投票

使用实例。将其添加到您的用户控件。

private static UserControlName _instance;
public static UserControlName Instance
{
    get
    {
        if (_instance == null)
            _instance = new UserControlName();
        return _instance;
    }
}

然后,将用户控件添加到您的表单。

this.Controls.Add(UserControlName.Instance);
//I prefer to use a panel then load the user controls on the panel so I don't have to set the location of the usercontrol

要调用BringToFront()SendToBack()方法,

UserControlName.Instance.BringToFront();
UserControlName.Instance.SendToBack();
© www.soinside.com 2019 - 2024. All rights reserved.