WinForm窗體之間傳值

 

vb.net在自制的窗體控件中彈出一個窗口再返回一個值 html

例如:正在自制一個控件A,在A中有一個按鈕BUTTON1和變量X.按下BUTTON1就會彈出一個已經制做好的WINDOS窗體FROM2,在FROM2中有textbox1,在關閉FORM2時,將textbox1中的值賦給控件A中的變量Xwindows

先設計好Form1和Form2。函數

在Private Class Form2中輸入
Public Event ChangeValue(ByVal value As String) '是string仍是其它的看你須要了

在Form2的Closed事件:post

Private Sub Form2_Closed() Handles Me.Closed
    RaiseEvent ChangeValue(TextBox1.Text)'若是是數值類型的話用下面這個:
    'RaiseEvent ChangeValue(Val(TextBox1.Text))
End Sub


在Form中定義x:
Dim x As String '是String仍是數值類型看你須要了,要和上面的統一
在Form1中寫一個處理值的函數。值哪來?別管它url

Private Sub ProcessValue(ByVal value As String) '記得統一
    x = value
End Sub


在Form1中Button1的Click事件中:spa

Private Sub Button1_Click() Handles Button1.Click
  Dim f2 As New Form2
  AddHandler f2.ChangeValue,AddressOf ProcessValue
  f2.Show()
End Sub

https://zhidao.baidu.com/question/553583369.html.net

 

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー設計

 

WinForm構造函數傳值 code

http://blog.csdn.net/zbssoft/article/details/5586306orm

 

在WinForms程序裏實現窗體傳值的最佳實踐

http://bbs.csdn.net/topics/360140208

 

windows form (窗體) 之間傳值小結

http://www.cnblogs.com/JoshuaDreaming/archive/2010/11/17/1880060.html

 

C# form 傳參數

http://www.cnblogs.com/Asa-Zhu/archive/2012/12/06/2805074.html

 ========================================

 

'本身的代碼

 

'個人例子

'彈出的子窗口 Public Class ChildForm Dim temp As String = "" Public Event returnValue(ByVal value As String) Public Sub New(ByVal Cd) InitializeComponent() temp = Cd End Sub Private Sub ChildForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load txtAAA.Text = temp '父窗口傳過來的值獲取到 End Sub Private Sub F12_Click(sender As Object, e As EventArgs) Handles F12.Click RaiseEvent returnValue("傳回父窗口的值") Me.Close() End Sub End Class
'父窗口 Public Class ParentForm Private Sub F2_Click(sender As Object, e As EventArgs) Handles F2.Click Dim childForm = New ChildForm("傳給彈出子窗口的值") childForm.Show() AddHandler childForm.returnValue, AddressOf ProcessReturnValue End Sub Private Sub ProcessReturnValue(ByVal value As String) txtTest.Text = value '子窗口傳回的值獲取到 End Sub End Class
相關文章
相關標籤/搜索