简体   繁体   English

具有唯一变量的 WinForms 多实例表单

[英]WinForms Multi-Instance Forms with unique variables

New to C#; C# 新手; have been a VB.NET/VBA developer for years.多年来一直是 VB.NET/VBA 开发人员。 Am currently working on an application for our off-site workers.我目前正在为我们的非现场工作人员申请。 I have a main switchboard form with a drop-down of project numbers.我有一个带有项目编号下拉菜单的主总机表格。 The user then has the ability to open a variety of form-based tools, to include a Budgets form.然后,用户可以打开各种基于表单的工具,包括预算表单。 On change of the drop-down, I store a Program-scoped class variable, cJob which has multiple properties (customer, location, etc).在更改下拉菜单时,我存储了一个程序范围的类变量 cJob,它具有多个属性(客户、位置等)。 On open of the Budgets form:在预算表打开时:

Form frm = new FieldBudgets.frmBudgets().Show();

I have a private static instance of cJob called meJob (new cJob).我有一个名为 meJob(新 cJob)的 cJob 私有静态实例。 When going back to the switchboard, the user, without closing that instance of the Budgets for, can open additional instances of the same Budget form with different project numbers selected.返回总机时,用户无需关闭该预算实例,就可以打开选择不同项目编号的同一预算表单的其他实例。

Here is my problem (sorry it took so long to get here): A Refresh button can update the data on the Budgets form, but the new meJob information from the last instance get carried to the other instance.这是我的问题(抱歉花了这么长时间才到这里):刷新按钮可以更新预算表单上的数据,但是来自最后一个实例的新 meJob 信息会被传送到另一个实例。 How can I keep these separate?我怎样才能把这些分开? I thought the new meJob would stick with the individual instances.我认为新的 meJob 会坚持单个实例。

As an aside, I do have a less than glamorous "solution" that involves a hidden textbox and reloading the new meJob on Refresh.顺便说一句,我确实有一个不太迷人的“解决方案”,它涉及一个隐藏的文本框并在刷新时重新加载新的 meJob。 If that is the best solution I get, so be it...如果这是我得到的最佳解决方案,那就这样吧......

MJ兆焦

Dictionary<string,FieldBudgets.frmBudgets> myBudgets = new Dictionary<string,FieldBudgets.frmBudgets>();
myBudgets.Add("Budget1",New FieldBudgets.frmBudgets());
myBudgets.Add("Budget2",New FieldBudgets.frmBudgets());
myBudgets.Add("Budget3",New FieldBudgets.frmBudgets());
myBudgets.Add("Budget4",New FieldBudgets.frmBudgets());

myBudgets["Budget2"].Show();

You might put any unique fields and/or properties in the constructor for frmBudgets.您可以在 frmBudgets 的构造函数中放置任何唯一的字段和/或属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM