Use forms copy

I have a form that pulls data, pops a number, does things. It works great.

the problem is in the code - I can only access one market at a time, and I want to have access to more than one.

I could duplicate the current form x 4, let's say this, so after logging in I could get access to 4 markets, not to 1. but the code is a little tight, and I would be stuck in any number of forms that I have instead in order to have the flexibility to replicate the initial form, and then access to another market.

the easiest and fastest way to do this would be to use some code that pops up a clone of an existing form, if such a thing is possible.

+4
source share
3 answers

If I understand what you need, you need something like this (the first part is VERY similar to Michael's answer):

In the shape of:

Public MarketCOde As String        ' whatever it is.

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

   MarketCOde = mktCode
End sub

Now that the code in your form needs to know in which market it works, it can link to MarketCode.

To create a form for working with a new market:

 Dim frmAsia As New FORMNAME("ASIA")

Since the form will FORBID the market code, we pass it when we create the form. We arent cloning a form, but creating instanceto work with different, but specific markets. Now keep reading, because the bad news is:

If all the code is embedded in the form, it should be reorganized to link to MarketCode, and not to hard-coded links, probably now. Then your application should start a new path, since mainform will not receive this critical MktCode argument from VB.

Project Properties. :

' 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

, ,

. . .

+3

, Properties MarketForm, , . MarketName, , .

MarketForm - ( , , )

Public Property MarketName As String

- ( ).

Dim myMarketForm1 As New MarketForm
myMarketForm1.MarketName = "Eastern"
myMarketForm1.Show()

Dim myMarketForm2 As New MarketForm
myMarketForm2.MarketName = "Central"
myMarketForm2.Show()
`... and so on
+2

I suspect you might be looking for this ...

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim frm As New Form1
    frm.Show()
End Sub

In this example, when a button is pressed Button1, it creates a copy Form1and displays it. A button can be pressed multiple times to create multiple copies Form1. The button can even be placed on Form1.

0
source

All Articles