Passing variables between windows forms in VS 2010

前端 未结 3 474
你的背包
你的背包 2021-01-14 03:34

I have two forms. Form 1 allows the user to pick an employee from a dropdown combo box. That employee is then passed onto Form 2 where the user enters additional information

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 04:13

    I am late but I think this answer can help.

    For example, Form1 named "menu" opens and passes variable to Form2 named "ordine". The variable to pass is "hotel"

    In menu on button_click

    Dim ordinef As New Ordine()
    
    If ordinef Is Nothing Then
        'control that form is not opened yet if open close before
        ordinef = New Ordine()
    Else
        ordinef.Close()
        ordinef = New Ordine()
    End If
    
    ordinef.hotel = hotel
    
    ordinef.Show()
    

    In Form2 (Ordine):

    Private Sub Ordine_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    public hotel as string
    
    msgbox hotel
    

    That's it!!

提交回复
热议问题