English 中文(简体)
结辩表
原标题:Closing dialog form closes parent form

我一直在处理奇怪的问题。 我在一个项目中使用KryptonForm。 我有一种形式(分析表1),我需要在纽扣地从这一表格中点击另一个形式。 该守则是:

void btn_click(object sender, EventArgs e)
{
    Visible = false;
    ShowInTaskbar = false;

    var f = new Form2();
    f.ShowDialog();

    Visible = true;
    ShowInTaskbar = true;
}

The problem is that when the Form2 closes it closes the Form1 also. I have tried setting DialogResult = DialogResult.None from Form2 but of no avail. Please help me.

我总是利用这一技术,这种情况从未发生。

最佳回答

是的,这一法典令人不安。 当用户关闭方言时,这是错误的。 然后,Windows必须找到另一个窗口,以关注这一问题。 你们看不到任何东西,你的主要窗口是看不到的。 然后,它取走了另一个人的窗口。 例如,Odds公司是好的,它将成为视觉演播室的一个窗口。 一个大的国家。 你的主要形式现在消失了。

你们需要确保你的主要窗户再次见到<>><>>><>>> 方言结束。 您可以通过向口头陈述事件的传记员来这样做。 例如:

    private void button1_Click(object sender, EventArgs e) {
        using (var dlg = new Form2()) {
            dlg.StartPosition = FormStartPosition.Manual;
            dlg.Location = this.Location;
            dlg.FormClosing += (s, ea) => this.Show();    // <=== Here
            this.Hide();
            if (dlg.ShowDialog() == DialogResult.OK) {
                // etc...
            }
        }
    }
问题回答

我知道这是个老员额,但我还是这样说,在我看来,(在我撰写本报告时)接受的回答根本不有用。 @blind Skwirl的回答使我到了主线。

经过20年的网络规划(自采用以来),我从未注意到英国国家航天中心拥有“诊断”财产。 我总是仅仅确定“cancelbutton”和“acceptbutton”性质的形式。 我在我的案例中发现,(由于我正在做大量 but子的复印件),我有一只 but子(不是表格),他们自己的“诊断”财产被定在“距离”上,这意味着我会把一个 but子点点点点点上,而对话会打开另一个方言,而对话会的“ok”的“ok子”结果却被设定为“cancel”,而“ALSO”的母体表的“str子”结果被设定为“cancel”,因此,“方言”会(由于他取消)和“Ement”结果而取消。

确实,你们所有各州都有自己对NONE的辩证财产(或你想要的实际适当环境)。

Bottom line, if a BUTTON (not the form) has its dialogresult property set to anything other than NONE, the form will close with that result when it is clicked (after any click event code has completed).

我希望这有助于人们走出那里。





相关问题
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.

热门标签