如何在MDI父表单中检索子表单上的数据时检查状态? [英] How to check the status while retrieve the data on child form in MDI parent form?

查看:64
本文介绍了如何在MDI父表单中检索子表单上的数据时检查状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我是一名新开发者,我试图找到有关在检索数据时检查子表单上的事件的信息。



示例:



我创建应用程序(MDI表单),并创建函数来检索数据显示在子窗体的datagridview控件上,但是检索数据有点延迟。



所以我想检查子窗体的状态是否已准备好或者,当用户点击父级的关闭按钮时,我想向用户显示警告或错误消息,例如:请在获取数据时等待一些。



#######



所以我该怎么办?请给我更多信息



谢谢



我的英语不是最强,对不起它



Godwin11



我尝试过:



如果你需要图片我会稍后拍摄



谢谢

解决方案

< blockquote>您需要在子表单中公开属性。现在MdiParent可以检查它是否正忙。



最简单的方法是使用界面。通过这种方式,您可以使用不同类型的子表单,界面可以轻松查询。

  interface  IFormState 
{
bool IsBusy { get ; }
}



在子表单上实现接口:

  public   partial   class  Form2:Form,IFormState 
{
< span class =code-keyword> public Form2()
{
InitializeComponent();
}

public bool IsBusy {获得; private set ; }

private void 但是SetBusyState_Click( object sender,EventArgs e)
{
IsBusy = true ;
}

private void Form2_FormClosing( object sender,FormClosingEventArgs e)
{
e.Cancel = IsBusy;
}
}



我用一个按钮来设置忙碌状态。此外,我已经挂上了孩子的 FormClosing 事件,以防止它在忙碌时关闭。



现在为MDI Parent:

  public   partial   class  Form1:Form 
{
public Form1()
{
InitializeComponent( );
var form = new Form2();
form.MdiParent = ;
form.Show();

}

private void Form1_FormClosing(< span class =code-keyword> object sender,FormClosingEventArgs e)
{
foreach var item in MdiChildren)
{
if (((IFormState)item).IsBusy)
{
e.Cancel = true ;
break ;
}
}
}
}



与子窗体一样,MDI父挂钩 FormClosing 事件。当被触发时,将迭代所有打开的子窗体并在子窗体忙时取消关闭。


最多开发一些数据流是一个架构问题。



您需要在关闭按钮的处理程序中获得有关文档状态的一些信息。所以通常你会使用一些指针来获取访问权限,而不是调用状态函数来为你提供状态。在这种情况下,通常会进行一些前向声明以避免循环包含标题。



示例

  class  MyDocument;  //  前向声明(不包含标题) ) 

class MyMainFrame
{
MyDocument * m_pDocument; // 重要:仅使用指针
}


Hi friends,

I am a new developer, I try to find information about checking the event on child form while retrieve the data.

Example:

I create the application (MDI form), and I create function to retrieve the data to display on datagridview control of "child form", but while retrieving data has delay a bit.

so I want to check the status of the child form is ready or not, when user click the close button of parent, I want to show a message to warning or error to users such as :"please wait a few while fetching data".

#######

so how do I do? please give me more information

Thank you

My English is not strongest, sorry about it

Godwin11

What I have tried:

If you need picture I will capture later

thank you

解决方案

You need to expose a property in the child forms. Now the MdiParent can check if it is busy.

The easiest way is to use an interface. This way you can have different types of child forms and the interface makes it easy to interrogate.

interface IFormState
{
    bool IsBusy { get; }
}


Implementing the Interface on the child form(s):

public partial class Form2 : Form, IFormState
{
    public Form2()
    {
        InitializeComponent();
    }

    public bool IsBusy { get; private set; }

    private void butSetBusyState_Click(object sender, EventArgs e)
    {
        IsBusy = true;
    }

    private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
        e.Cancel = IsBusy;
    }
}


I have used a button to set the busy state. Also, I've hooked the FormClosing event of the child to also prevent it from closing if busy.

Now for the MDI Parent:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        var form = new Form2();
        form.MdiParent = this;
        form.Show();

    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        foreach (var item in MdiChildren)
        {
            if (((IFormState)item).IsBusy)
            {
                e.Cancel = true;
                break;
            }
        }
    }
}


Like the child forms, the MDI parent hooks the FormClosing event. When fired, will iterate through all the open child forms and cancel the closing if a child form is busy.


At most it is an architectural problem to develop some data flow.

You need in the handler of the close button some information about the state of your document. So normally you work with some pointers to get access and than call a state function which gives you the state. In such cases often some "forward declaration" is done to avoid cyclic inclusion of header.

Example

class MyDocument;//forward declaration (without header inclusion)

class MyMainFrame
{
  MyDocument *m_pDocument;//important: only use pointers
}


这篇关于如何在MDI父表单中检索子表单上的数据时检查状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆