我正在编写一个代码,其中包含一个包含多个用户控件的表单。我使用表单中的方法在这些用户控件之间切换。现在我想在其中一个用户控件中使用该方法,并将表单的用户控件之一作为参数提供。
public partial class Homescreen : Form
{
private Control ActiveUserControl { get; set; }
public Homescreen()
{
InitializeComponent();
//default user control
this.ActiveUserControl = ucAccount1;
}
public void SwitchUserControl(Control controls)
{
ActiveUserControl.Visible = false;
controls.Visible = true;
this.ActiveUserControl = controls;
}
private void pbChat_Click(object sender, EventArgs e)
{
SwitchUserControl(ucChats1);
}
}
public partial class ucChats : UserControl
{
public ucChats()
{
InitializeComponent();
}
private void btnBekijk_Click(object sender, EventArgs e)
{
//this is how i imagined it, but obviously doesnt work
Homescreen.switchusercontrol(Homescreen.ucOtherUserControl);
}
}
我怎么能实现这个目标?