在我的项目中,它包含两页。那些是Form1.cs,myusercontrol1.cs。
Form1有Button。在Button_click事件中,需要将Form1重定向到myuserontrol1.cs页面。
这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
// Code1
var destinationform = new myusercontrol1();
destinationform.Show();
// Code2
myusercontrol1 destinationformobj = new myusercontrol1();
destinationformobj.Show();
}
但它永远不会重定向到myusercontrol1.cs页面
是否可以从Form重定向到UserControl页面?
提前致谢
答案 0 :(得分:1)
根据评论,您可以通过表单解决问题:
public frmUserControl : Form
{
private UserControl control;
public frmUserControl(UserControl control)
{
this.control = control;
this.Load += frmUserControl_Load;
}
public frmUserControl_Load(object sender, EventArgs e)
{
this.Controls.Add(control);
}
}
您还需要处理一些事情,例如新表单的大小以及表单内用户控件的位置。我试图找到我的旧代码,但它太旧了,我现在没有。所以我希望它有所帮助:)