Move one form to another winforms - C#

2020-03-03 09:34发布

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

标签: winforms mdi
5条回答
干净又极端
2楼-- · 2020-03-03 09:45

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

查看更多
3楼-- · 2020-03-03 09:50

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?

查看更多
放荡不羁爱自由
4楼-- · 2020-03-03 09:52

Instead of hide use close option.

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

or simply

this.Close();
查看更多
我命由我不由天
5楼-- · 2020-03-03 10:00

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();
查看更多
The star\"
6楼-- · 2020-03-03 10:02

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();
查看更多
登录 后发表回答