本文介绍了使用.ShowDialog()的多文档界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为frmMain的表单,它是一个MDI容器.

frmMain显示frmInventory的一个实例.然后,该实例出现在frmMain中.从frmInventory上的菜单(添加到frmMain的菜单中),我创建frmAddComm的实例.

但是,frmAddComm基本上是一个添加新项窗口,提示输入数据,然后使用该窗口创建一个新项以发送回frmInventory.

尽我所能,我无法使frmAddComm出现在frmMain的范围内.

我试过了:

I have a form, called frmMain, which is a MDI container.

frmMain shows an instance of frmInventory. That instance then appears within frmMain. From a menu on frmInventory (that is added to frmMain''s menu) I create an instance of frmAddComm.

However, frmAddComm is basically an add new item window, prompting for input data, which it then uses to create a new item to send back to frmInventory.

Try as I might, I cannot get frmAddComm to appear within the bounds of frmMain.

I have tried:

<br />
<pre>frmAddComm addComm = new frmAddComm();<br />
addComm.MDIParent = this.Owner;  // this referring to frmInventory<br />
addComm.Show();</pre><br />







and

<br />
<pre>frmAddComm addComm = new frmAddComm();<br />
addComm.MDIParent = this.Owner;<br />
addComm.ShowDialog();   // what I really want to use</pre><br />







and

<br />
<pre>frmAddComm addComm = new frmAddComm();<br />
addComm.MDIParent = (MDIClent)this.Parent;<br />
// addComm.ShowDialog;    // this throws and exception<br />
addComm.Show();       // shows within bounds of frmMain</pre><br />



但是,最后一个选项不会暂停并等待addComm.Close()发生,因此将继续通过我的if语句来确定是否按下了OK或Cancel,因此默认为cancel.

对于程序功能,我有以下内容:



The last option however does not pause and wait for addComm.Close() to happen, and thus continues on right through my if statement to determine if OK or Cancel was pressed, thus defaulting to cancel.

For program functionality I have this:

frmAddComm addComm = new frmAddComm();

addComm.MdiParent = this.Owner;
addComm.ShowDialog();
if (addComm.DialogResult == DialogResult.OK)
{
   qc_Inventory.Add(addComm.NewCommunicator);
   ManageInventory(tabInventory.SelectedIndex);
}



但是,它没有将addComm放在frmMain的范围之内,这正是我想要的.



However, it does not put addComm within the bounds of frmMain, which is what I want.

推荐答案


这篇关于使用.ShowDialog()的多文档界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 00:09