[英]Trouble of hiding Form C#
以前我所做的是:
this.Hide();
Newform a = new Newform();
a.Show();
然后問題應該解決了,但是現在不起作用了。 我測試了是否使用按鈕來隱藏窗口,它可以正常工作。 但是我不想在表格上顯示一個按鈕。
該表格只是在等待USB輸入並進入下一個窗口。 (無按鈕)。 這是我的代碼:
private void Usbauthentication_Load(object sender, EventArgs e)
{
Usbdetected();
try
{
watcher.EventArrived += new EventArrivedEventHandler(this.WaitForUSBChangeEvent);
watcher.Query = new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2");
watcher.Start();
}
catch (ManagementException a)
{
Console.WriteLine(a);
}
}
public void WaitForUSBChangeEvent(object sender, EventArrivedEventArgs e)
{
this.Usbdetected();
}
public void Usbdetected()
{
list = conn.Select();
for (int i = 0; i < drives.Count(); i++)
{
drivelist.Add(drives[i].Name.Replace(@"\", ""));
if (list.Contains(usb.getSerialNumberFromDriveLetter(drivelist[i])))
{
store = i;
this.Hide();
Login a = new Login();
a.Show();
break;
}
}
}
這樣的事情應該可以解決問題:
var form2 = new Form2();
form2.Shown += (o, e) => this.Hide();
form2.Show();
您還需要確保在關閉新表單時關閉原始表單:
form2.FormClosed += (o,e) => this.Close();
因此,總的來說,您需要編寫:
Newform a = new Newform();
a.Shown += (o, e) => this.Hide();
a.FormClosed += (o, e) => this.Close();
a.Show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.