免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
Board logo

標題: Form2應用須知 [打印本頁]

作者: mhfo    時間: 2014-2-20 08:59     標題: Form2應用須知

以下是其中一種範例
Public Class Form1
        Sub New()

                ' 此為設計工具所需的呼叫。
                InitializeComponent()

                ' 在 InitializeComponent() 呼叫之後加入任何初始設定。
                AddHandler TextBox1.Click, AddressOf TextBox_Click
                AddHandler TextBox2.Click, AddressOf TextBox_Click
                AddHandler TextBox3.Click, AddressOf TextBox_Click
        End Sub

        Private Sub TextBox_Click(sender As Object, e As System.EventArgs)
                Dim frm As Form2 = New Form2()
                frm.PassValue = DirectCast(sender, TextBox)
                frm.Show()
        End Sub
End Class

Public Class Form2

        Private _passvalue As TextBox
        Public WriteOnly Property PassValue As TextBox
                Set(value As TextBox)
                        _passvalue = value
                End Set
        End Property

        Sub New()

                ' 此為設計工具所需的呼叫。
                InitializeComponent()

                ' 在 InitializeComponent() 呼叫之後加入任何初始設定。
                AddHandler Button1.Click, AddressOf Button_Click
        End Sub


        Private Sub Button_Click(sender As System.Object, e As System.EventArgs)
                _passvalue.Text &= "1"
        End Sub
End Class

有一個寫 Visual Basic 要注意的地方是, 少用 Form2.Show()  這種方式, 儘量另外宣告並產生執行個體來用 (到了使用多執行緒時,  Form2.Show() 這種寫法會帶來很多麻煩 )




歡迎光臨 魚骨頭的雲端圖書館 (http://mhfo.hotbbs.info/) Powered by Discuz! 7.0.0