如何将form1更改为form2? [英] how do you change form1 to form2?

查看:187
本文介绍了如何将form1更改为form2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在form1中有一个简单的按钮,我很难过,当您单击form1中的按钮时,form1会变成form2.我唯一能做的就是在新窗体上打开form2.我忘了怎么做,我需要一个人来帮助我慢跑我的记忆!

谢谢.

I have a simple button in form1, I''m having a hard time making it that when you click on the button in form1 form1 will change into form2. The only thing I can do is make form2 open on a new form. I forgot how to do this and I need someone to help me jog my memory!

Thanks.

推荐答案

您实际上不能将Form1更改为Form2-它们通常是单独的类,不能从一个类突变"为另一个类.
您可以通过两种方法获得视觉效果.

首先是使它们具有相同的大小和形状,然后将新表单StartPosition设置为Manual.然后,您可以设置Loctation属性,使其与Form1匹配.然后,您可以显示Form2,然后隐藏Form1-除非先隐藏Form1,否则不要尝试在Form2上使用ShowDialog!如果执行此操作,则必须提供一种返回Form1的方法,或者提供另一种终止应用程序的方法-关闭Form2不会这样做.一种方法是处理Form2 FormClosing事件,然后关闭Form1或重新显示它.

另一种方法是将整个表单放入UserControl并将其显示在Form曲面上.当需要交换到"Form2"时,只需将"Form1" UserControl Visible属性设置为false,将"Form2"设置为true.就像魔术一样,形式似乎也在改变!

就个人而言,我倾向于使用后一种方法.
You can''t actually change Form1 into Form2 - they are normally separate classes and can''t be "mutated" from one into the other.
There are a couple of ways you can get that visual effect though.

The first is to make them the same size and shape, and set the new form StartPosition to Manual. You then set the Loctation property so that it matches the Form1. You can then Show the Form2, and Hide Form1 - do not try to use ShowDialog on Form2 unless you Hide Form1 first! If you do this, you must provide a way to return to Form1, or a different way to terminate the application - closing Form2 will not do that. One way is to handle the Form2 FormClosing event, and either Close Form1, or re-show it.

The other way is to put the whole of your form into a UserControl and display that on the Form surface. When you need to swap to "Form2" you just make the "Form1" UserControl Visible property false, and the "Form2" one true. Like magic, the form appears to change!

Personally, I tend to use the latter method.


这篇关于如何将form1更改为form2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆