帮助我进行主要表单和子表单之间的交互操作 [英] help me for interactive operation between main forms and child forms

查看:50
本文介绍了帮助我进行主要表单和子表单之间的交互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑如何实现主表单及其子表单之间的交互操作.例如,我的项目中有一个主表单和子表单.
主要形式如下(仅是一个简化示例):

I''m confused how to realize the interactive operation between main forms and its child forms.for example there is a main form and child form in my project.
the main form is below(just a simplified example):

namespace WindowsFormsApplication1
{
    partial class Form1
    {
        private System.ComponentModel.IContainer components = null;
 
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.RichTextBox richTextBox1;
        private System.Windows.Forms.StatusStrip statusStrip1;
        private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1;
        private System.Windows.Forms.Label label1;
    }
}



当单击主窗体上的button1时,将显示一个子窗体,然后用户可以通过单击子窗体上的按钮来开始对硬盘上的记录文件进行分析.同时,在子窗体上有一个复选框提供了记录中使用的条件.文件分析.
我要实现的目的是:在分析过程中,中间结果和最终结果都显示在主窗体的ricktextbox1中,主窗体的进度条将显示处理进度.

如果以上所有内容都以一种形式进行操作,我可以处理.如何进行分析
在子窗体上进行操作并在主窗体上显示信息,因为必须完成许多分析和模拟工作,因此我的项目中有很多子窗体,我想在同一位置显示所有这些分析结果(主窗体上的richtextbox1)并非在每个子窗体上都使用



When button1 on main form is clicked ,one child form will show ,then user may start the analysis of record file on hard disk by clicking button on child form.Meanwhile there are some checked box on child forms which supply for the conditions used in record file analysis.
The purpose i want to achieve is :the intermediate and final results are all displayed in the ricktextbox1 on main form during the analysis and the progressbar on main form will show the processing progress.

I can deal with it if all of above is operated on one form. how can i run analysis
operation on child form and show information on main form because there are many analysis and simulation works must be done,so there are many child forms in my projects and i want to show all these analysis results on the same place(richtextbox1 on main form) not on every child forms

推荐答案

以子窗体中的形式获取计时器对象,并定期将一些数据更新传递回您的父窗体.按照链接来学习如何将数据传递回调用表单! :)


将数据传递回调用表单 [
take timer object in child form, and pass some data updates back to your parent form, at regular intervals. follow the link to lean how to pass data back to calling form!! :)


Pass data back to the calling form[^]


mark as answer if solves your problem.


您可以看到此在之间传递值带有C#和VB.NET示例的.NET 1.x中的表单,它对于您的问题很有用;)
You can see this Passing Values between Forms in .NET 1.x with C# and VB.NET examples, it is useful for your problem ;)


让我们假设您想将数据集从对话框返回到主窗口表格,您需要执行以下步骤

1-在您的主窗体上创建一个公共DataTable对象\
2-在对话框形式上创建单个参数构造函数.


let suppose you want to return a dataset from dialog to main form you require following steps

1- create a public DataTable object on your main form\
2- create a single argument constructor on dialog form.
i.e.

class Child
{
 DataTable myDt = new DataTable("RecordSet");
 MainForm frmMain = null;
 Child(MainForm frm)
 {
   frmMain = frm;
 }
}



3-转到对话框形式(您说子形式)时,将主要形式的对象传递给它.





3- while moving to dialog form (you saying child form) pass the object of main form to it.

i.e.

Child frmChld = new Child(this);
frmChild.ShowDialog()



4-现在,您检索结果并将结果分配给frmMain的DataTable,然后关闭表单.




4- now you retrieve results and assign results to DataTable of frmMain and then close the form.
i.e.

frmMain.dtCheck = myDt;
this.close();



5-现在您可以在frmMain上访问您的数据表,您刚从子表单中填充了该数据表

希望它对您来说是可以理解的.



5- now you can access your datatable on frmMain you just populated from child form

hope it will be understandable for you.


这篇关于帮助我进行主要表单和子表单之间的交互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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