带到前用户控制 - 窗口表单



我有一个称为moviedetails的用户控件,我将其拖到主表单中,但是当我编写MovieDetail.BringDetails();时,我会得到此错误:

'moviedetails'不包含" bringtofront"的定义。

如何访问Bringtofront方法?

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

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();

最新更新