使用表格副本 [英] Use Copies of Forms

查看:68
本文介绍了使用表格副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种形式,可以提取数据,处理数字,执行操作。它完美地工作。

i have a form that pulls in data, crunches numbers, does things. it works perfectly.

问题在于代码是我一次只能进入一个市场,而我想具有访问多个市场的能力。

the problem is the code is i can only access one market at a time and i want to have the ability to access more than one.

我可以复制当前表格x 4,也就是说,登录后我可以进入4个市场,而不是1。但是代码有点密集,我会坚持但是,我有很多表格是硬连线的,而不是具有复制初始表格然后进入另一个市场的灵活性。

i could duplicate the current form x 4 let's say, so then after i login i could have access to 4 markets, instead of 1. but the code is a little dense, and i would be stuck with however many forms i have hardwired, instead of having the flexibility to replicate the initial form, and then access another market.

最简单,最快的方法是如果可能的话,请使用一些代码来弹出现有表单的副本。

the simplest and fastest way to accomplish this would be to use some code that would 'pop-up' a clone of the existing form, if such a thing is possible.

推荐答案

如果我了解您的要求,那么您会想要这样的东西(第一部分非常类似于迈克尔的答案) :

If I understand what you are after, you want something like this (first part is VERY similar to "Michael's" answer):

格式为:

Public MarketCOde As String        ' whatever it is.

Public Sub New(mktCode As String)
   ' leave this line alone
   InitializeComponent

   MarketCOde = mktCode
End sub

现在表单中的任何地方的代码需要知道它在哪个市场上工作,它都可以引用 MarketCode

Now anywhere the code in your form needs to know which market it is working on, it can reference MarketCode.

创建与新市场兼容的表单:

To create a form to work with a new market:

 Dim frmAsia As New FORMNAME("ASIA")

由于表单将需要市场代码,因此我们在创建表单时将其传递。我们没有克隆该表单,但是创建了一个 instance 表单以与不同但特定的市场一起使用。现在,继续阅读,因为这是个坏消息:

Since the form will REQUIRE a market code, we are passing it when we create the form. We arent cloning the form, but creating an instance of it to work with different, but specific, markets. Now, keep reading because here is the bad news:

如果所有代码都嵌入在表单中,则必须将其重构为引用MarketCode而不是硬编码引用可能现在在那里。接下来,您的应用程序需要一种新的启动方式,因为主窗体不会从VB获得关键的MktCode arg。

If all the code is embedded in the form, it will have to be refactored to reference MarketCode instead of the hardcoded references likely there now. Next, your app needs a new way to start since the mainform wont get that critical MktCode arg from VB.

最好的方法是添加一个市场选择器表单,并在Project Properties中将其作为启动表单。添加按钮以创建所需的每个新市场表单:

The best thing is to add a market picker form, and make that the start up form in Project Properties. Add buttons to create each new market form you need:

' this is a new button on a new form to make Market Form instances.
Sub button1_click......

  ' USE THE ACTUAL FormName from your code!
  Dim frmCentral as New FORMNAME("CENTRAL")   
  frmCentral.Show

 End Sub

' each button makes a new market form,
Sub button2_click......                     ' NOTE: Btn 2!

  ' the FormName from your code
  Dim frmAsia as New FORMNAME("ASIA")   
  frmAsia.Show

 End Sub

一个按钮,一个表单实例名称,一个市场

这也是启动第一个启动表单。确保将其设置为项目属性中的启动表单。

This is also the startup form to launch the first one. Be sure to set it as the startup form In Project Properties.

这篇关于使用表格副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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