将一个窗体移动到另一个 winform - C#

发布于 2024-08-05 17:08:10 字数 389 浏览 2 评论 0原文

我有2个winforms Form 1和Form 2。我在form1中有button1,当我从form1单击button1时,我显示form2。

            Form2 ins = new Form2();
            ins.MdiParent = this.MdiParent;
            this.Hide();
            ins.ShowDialog();

当单击button1时,我隐藏form1以显示form2。这会产生闪烁效果,我需要消除这种闪烁。我如何打开/重定向到另一个表单(我应该一次只显示一个表单,并且不应该显示任何顶部菜单,例如(如果我使用 MDIParent 表单)。只有一个活动表单。

谢谢, 卡西克

I have 2 winforms Form 1 and Form 2. I have button1 in form1, when i click on button1 from form1 i display form2.

            Form2 ins = new Form2();
            ins.MdiParent = this.MdiParent;
            this.Hide();
            ins.ShowDialog();

I hide the form1 to display form2 when button1 is clicked. This creates a flicking effect and i need to remove this flicking. How do i open/redirect to another form (i am supposed to show only one form at a time and am not supposed to show any top menu like (if i use MDIParent form). Just one active form.

Thanks,
Karthick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一身仙ぐ女味 2024-08-12 17:08:10

这听起来有点像您正在尝试创建一个 Web 风格的 UI,其中用户从一个“页面”(由表单表示)步进到另一个“页面”。

与其使用单独的表单实现这样的 UI,不如使用托管在单个父表单上的 UserControls 来实现。

请阅读这篇 MSDN 文章,其中包含示例代码的下载。这是设计此类用户界面的一个很好的演练:

IUI 和 Web 样式导航Windows 窗体,第 1 部分

Windows 窗体中的 IUI 和 Web 样式导航,第 2 部分

编辑

如果您打算显示两个单独的表单,是否有任何理由需要以模态方式显示第二个表单?你能不能简单地显示它然后隐藏原来的?

form2.Show();
form1.Hide();

...或者您是否还有另一种形式,form1 和 form2 都是“模态”的?

It sounds a bit like you're trying to create a web-style UI where the user steps from one "page" (represented by a Form) to another.

Rather than implementing a UI like this with separate forms, you're better off doing it with UserControls hosted on a single parent form.

Have a read of this MSDN article, which includes a download with sample code. It's a great walkthrough for designing that kind of user interface:

IUIs and Web-Style Navigation in Windows Forms, Part 1

IUIs and Web-Style Navigation in Windows Forms, Part 2

Edit

If you're intent on showing two separate forms, is there any reason you need to show the second one modally? Can you not simply show it and then hide the original?

form2.Show();
form1.Hide();

... or do you have yet another form that both form1 and form2 are "modal" to?

酒解孤独 2024-08-12 17:08:10

从一个页面 (form1) 转移到另一页面 (form2)
假设 form1 包含一个名为“SAVE”的按钮
我们必须在“SAVE”按钮的单击事件中编写以下代码

form2 f2=new form2();
f2.Show();

To transfer from one page (form1) to another (form2)
suppose form1 contain a button named "SAVE"
we have to write the following code in click event of the "SAVE" button

form2 f2=new form2();
f2.Show();
森罗 2024-08-12 17:08:10

我认为 winforms 上有一个属性,如果你想在任务栏上显示它或不显示它。

I think there is a property on winforms if you would like to show it on the task bar or not.

药祭#氼 2024-08-12 17:08:10

我可以澄清您对如何从 form1 重定向到 form2 的疑问,

例如:
在form1中放置一个链接,然后在其中写入以下代码

form2 ins=new form2();
ins.show();

I can clarify your doubt about how to redirect from one form1 to form2

for example:
place a link in form1 and then write following code in it

form2 ins=new form2();
ins.show();
晨光如昨 2024-08-12 17:08:10

使用关闭选项代替隐藏。

Form1 formObject = new Form1();
formObject.Close();

或者简单地

this.Close();

Instead of hide use close option.

Form1 formObject = new Form1();
formObject.Close();

or simply

this.Close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文