English 中文(简体)
如何从主要形式隐藏一种形式
原标题:How to hide a form from the main form

我每天都在敲响我的节目,我有一个问题,隐藏着一种将叫“请等”的表格。

例如:

    private void button12_Click(object sender, EventArgs e)
    {
        form2 wait = new form2();
        pw.Show();
    }
    private void button13_Click(object sender, EventArgs e)
    {
        form2 wait = new form2();
        pw.Hide();
    }

这不会奏效,尽管我确信,这只是临时C#编程的头号新闻。 是否有简单的方法去做我试图做什么? 我尝试在网上搜寻,我确实发现了一些东西,尽管我知道他们试图做什么。 我将找到一个例子来显示你,但我关闭了一页——典型。 然而,我认为他们试图推翻示威,让你控制how子。

最佳回答

该代码是按您的预计操作的,因为form2 载于>button12_Click/code>内的代码不同于form2 载于>>的代码> button13_click。 您使用<代码>新的通知 关键词两倍。 因此,在<代码>button13_click<>/code>上,你正在创建新的<代码>form2,然后躲藏起来,尽管你甚至显示它!

相反,你可以创建单一<代码>form2。 例举:

//define this code outside both of the methods below
form2 _waitForm = new form2();

private void button12_Click(object sender, EventArgs e)
{
    _waitForm.Show();
}
private void button13_Click(object sender, EventArgs e)
{
    //this will hide the same form2 that was shown in button12_Click
    _waitForm.Hide();
}
问题回答

暂无回答




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签