在兩個窗體中傳值的方法。。。

2021-03-31 08:57:00 字數 1557 閱讀 2004

form1 中 new form2的時候new form2(this),form2的建構函式中接受form1的引用 public form2(form1 frm1),然後定義乙個from1型別變數接受引數,就可以使用form1了,要使用其中的控制項需要在form1中把他們定義成public就行。

form1:

using system;

using system.drawing;

using system.collections;

using system.***ponentmodel;

using system.windows.forms;

using system.data;

namespace f2parent

///

/// clean up any resources being used.

///

protected override void dispose( bool disposing )

}base.dispose( disposing );

}#region windows form designer generated code

///

/// required method for designer support - do not modify

/// the contents of this method with the code editor.

///

private void initialize***ponent()

#endregion

private void button1_click(object sender, system.eventargs e)}}

form2

using system;

using system.drawing;

using system.collections;

using system.***ponentmodel;

using system.windows.forms;

namespace f2parent

///

/// clean up any resources being used.

///

protected override void dispose( bool disposing )

}base.dispose( disposing );

}#region windows form designer generated code

///

/// required method for designer support - do not modify

/// the contents of this method with the code editor.

///

private void initialize***ponent()

#endregion

private void button1_click(object sender, system.eventargs e)}}

兩個窗體的值傳遞

目的 第乙個窗體 主窗體mainform 獲取第二個窗體 資料窗體dataform 的輸入值 方法一 推模式,主窗體公開方法!即把主窗體的例項推給資料窗體 步驟 1.主窗體新增公開方法 2.資料窗體新增帶引數的建構函式 3.資料窗體按鈕事件呼叫公開方法,傳遞使用者的輸入值 4.主窗體按鈕事件開啟資料...

兩個靜態頁面中存值,傳值

使用了h5的localstorage.setitem 需要注意的是首先要把物件用json.stringify 轉一下,下面是 localstorage.setitem userinfo json.stringify data 下面是接收 var res null res json.parse loc...

兩個WebUserControl之間傳值

兩個webusercontrol之間傳值,網上的 有,直接從usercontrol1中定位到usercontrol2的寫法,偶合性很強,感覺不太好,於是提供另外的寫法。用乙個容器container.aspx來放兩個webusercontrol,分別是uc1和uc2。現在假設要從uc1的乙個事件觸發,...