从表单传递对象至中 [英] Passing Object from Form to Form

查看:195
本文介绍了从表单传递对象至中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当大的CRUD winform应用程序被设置为显示嵌入形式的TabControls。我想对Person对象,(有)招生,(有)计划持有和跟踪信息,因为它们与形式的互动。我如何做到这一点?我发现了一个建议,声明Person对象在我的的Program.cs 像这样 - >

I have a fairly large CRUD winform app that is set up to display forms embedded in tabcontrols. I want to have objects for Person,(has a) Enrollment,(has a) Plan that hold and track the information as they interact with the forms. How do I accomplish this? I found a suggestion to declare the Person object in my Program.cs like so -->

internal static class Program
{
    public static CurrentPerson _CurrentPerson;

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    private static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new FrmWWCShell());
    }
}

,然后在 Search.cs - >

and then on the Search.cs -->

 Program._CurrentPerson = new CurrentPerson
                                     {
                                         PersonID = Convert.ToInt32(pID),
                                         LastName = lName,
                                         FirstName = fName,
                                         SocialSn = sSN,
                                         MiddleName = mName,
                                         BirthDate = Convert.ToDateTime(bDate)
                                     };

这是最好的方法是什么?还有一组数据需要被的填写的从数据库中,一旦他们做出这一选择的搜索页面上。怎么样声明该对象的每个表单上,并通过它的一些方式?对象正在慢慢建,因为他们进步。首先,他们搜索作为一个人的名字,并选择他们将与谁。然后,他们可以有扩招工作。选择一个报名后,他们将能够与有计划进行交互。

Is this the best way? There is still a bunch of Data that needs to be filled in from the database once they have made this selection on the Search page. What about declaring the object on each form and passing it some way? The object is slowly "built" as they progress. First they Search for someone by name and select who they will work with. Then they can work with there Enrollments. After selecting an Enrollment they will be able to interact with there Plans.

我将不胜感激这里的任何指导,这个范围已经离开我的经验不足的头纺纱...

I would be grateful for any guidance here as the scope of this has left my inexperienced head spinning...

推荐答案

您将需要单独的数据,逻辑和图形用户界面。

You will need to seperate your data, logic and GUI.

窥视的Model-View-Controller模式

如果你认为它太复杂,你的情况,你可能只是建立一个中央控制器类来保存中央数据。通过在每一个表单构造这个对象,你就大功告成了。

If you think it's too complex in your case you might just create a central controller class to hold the central data. Pass on this object in every form constructor and you're done.

这篇关于从表单传递对象至中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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