![](/img/trans.png)
[英]Call Webmethod in Usercontrol.cs from Usercontrol.ascx javascript
[英]Button click - redirect to UserControl.cs page in Windows Form
在我的項目中,它包含兩個頁面。 這些是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頁面
是否可以從窗體重定向到UserControl頁面?
提前致謝
好的,根據評論,您可以執行以下操作以使用表單解決問題:
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);
}
}
您還必須注意一些新內容,例如新表單的大小以及用戶控件在表單中的位置。 我試圖為此找到我的舊代碼,但是它太舊了,我現在沒有。 所以我希望它會有所幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.