利用委託的方法實現2個窗體之間的通訊的乙個小練習

2021-07-11 14:20:36 字數 1215 閱讀 9416

----------- 傳送端窗體**-------------

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.threading.tasks;

using system.windows.forms;

namespace 用委託的方法進行2個窗體之間的通訊

public delegateconnect send;//第二步:定義乙個委託的物件

//這裡為什麼沒有直接用delegateconnect send=new delegateconnect(方法名);

//因為這裡需要傳的方法引數是在form1(接受端)定義的,並且在form1裡面進行繫結

int count = 0;

private void button1_click(object sender, eventargs e)

}private void form2_load(object sender, eventargs e)

}public delegate void delegateconnect(string str);//第一步:宣告乙個委託的類

}----------- 接收端窗體**-------------

using system;

using system.collections.generic;

using system.componentmodel;

using system.data;

using system.drawing;

using system.linq;

using system.text;

using system.threading.tasks;

using system.windows.forms;

namespace 用委託的方法進行2個窗體之間的通訊

private void form1_load(object sender, eventargs e)

public      void receive(string str)}}

Winform中利用委託實現窗體之間的傳值

點選開啟按扭,開啟傳輸值窗體 public partial class form1 form 2 78public void getvalue string strv 9 1213 private void button1 click object sender,eventargs e 1421 輸...

winform 利用委託實現窗體傳值

父窗體 form1 有個 textbox1.text 有個button1 子窗體 form2 有個 textbox1.text 有個button1 修改form1 的textbox1.text 點選form1的 button1,彈出form2,點選form2 的button 結果 form2的 te...

2個窗體之間的通訊

在乙個form裡改變textbox時 另外乙個form裡textbox的值 也隨之變化 form1 包含個textbox1 public event eventhandler textchangevalue addremove form2 包含乙個textbox2 和button1 public v...