winform怎么跳转新窗口
时间: 2023-10-10 21:12:45 浏览: 92
在WinForm中跳转到新窗口可以通过以下几种方法实现:
方法一:
using System.Threading;
//打开另一个窗口的同时关闭当前窗口
Thread th = new Thread(delegate ()
{
new IndexForm().ShowDialog();
});
th.Start();
this.Close();
方法二:
IndexForm indexForm = new IndexForm();
this.Hide();
indexForm.ShowDialog();
this.Dispose();
以上是两种常用的方法,你可以根据具体的需求选择适合的方式来实现窗口跳转。
相关问题
winform跳转到新窗体
可以使用以下代码实现:
```
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
this.Hide();
}
```
这段代码可以在点击按钮时跳转到一个名为Form2的新窗体,并隐藏当前窗体。
winform 打开新窗口带参数
你可以使用以下代码在 Winform 中打开一个新窗口并传递参数:
1. 在目标窗口中定义一个构造函数,用于接收参数。
```csharp
public partial class TargetForm : Form
{
private string param;
public TargetForm(string param)
{
InitializeComponent();
this.param = param;
}
// ...
}
```
2. 在源窗口中创建实例并传递参数。
```csharp
private void OpenTargetForm(string param)
{
TargetForm targetForm = new TargetForm(param);
targetForm.Show();
}
```
这样就可以在打开新窗口时传递参数了。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)