简体   繁体   English

C#:获取按钮以显示预设表单

[英]C#: Getting a button to display a preset form

I (currently) have two forms, one that needs to call the other. 我(当前)有两种形式,一种需要调用另一种。 In other words, by clicking a certain button in Form1 , Form2 needs to "pop up", like a dialog box. 换句话说,通过单击Form1的某个按钮, Form2需要像对话框一样“弹出”。 I know I have to get a reference in both forms, but I'm not entirely sure how to do this. 我知道我必须同时获得两种形式的参考,但是我不确定如何做到这一点。 What is a decent tutorial/beginner site to learn about GUIs in C#? 什么是一个不错的教程/入门网站,以了解C#中的GUI?

You can try this: 您可以尝试以下方法:

protected void Button1_Click(object sender, EventArgs e)
{
    Form2 myForm = new Form2();
    myForm.ShowDialog();
}

ShowDialog forces the user to close that window before s/he can access the rest of the application. ShowDialog强制用户在他/她可以访问应用程序的其余部分之前关闭该窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM