第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在winform之間傳遞變量

在winform之間傳遞變量

智慧大石 2019-12-06 15:10:02
我在Windows.Forms應用程序中遇到有關(guān)委托的問題。有兩種形式:主窗體,其中有一個名為“設(shè)置”的按鈕。“設(shè)置”形式,這是“子”形式。當我單擊主窗體中的“設(shè)置”按鈕時,它將打開“設(shè)置”窗體的一個實例。我的問題是,當我打開變量時,需要將其傳遞給“設(shè)置”表單。這樣新表單將顯示變量文本。我不知道如何在子“設(shè)置”表單中檢索信息。我通過遵循在線教程來做到這一點,但無法從教程中了解如何讀取目標表單中的信息。到目前為止,這是我做的主要形式的代碼:public partial class MainForm : Form{    /// <summary>    /// delegate to send data between forms    /// </summary>    public delegate void PageInfoHandler(object sender, PageInfoEventArgs e);    /// <summary>    /// event of the delegate    /// </summary>    public event PageInfoHandler PageInfoRetrieved;    //other stuff, events blabla    private void toolStripBtnSettings_Click(object sender, EventArgs e)    {        PageInfoEventArgs args = new PageInfoEventArgs(SomeString);        this.OnPageInfoRetrieved(args);        SettingsForm settingsForm = new SettingsForm();        settingsForm.ShowDialog();      }    private void OnPageInfoRetrieved(PageInfoEventArgs args)    {        if (PageInfoRetrieved != null)            PageInfoRetrieved(this, args);    }}
查看完整描述

3 回答

?
飲歌長嘯

TA貢獻1951條經(jīng)驗 獲得超3個贊

將所需的任何信息傳遞到“設(shè)置”表單的構(gòu)造函數(shù)中,并提供所需的訪問器方法。


public class SettingsForm : WinForm

{

    private string m_Data;

    private int m_nExample = 0;


    // ctor

    public SettingsForm(string _data)

    {

        m_Data = data;  // you can now use this in SettingsForm

    } // eo ctor


    public int Example {get{return(m_nExample);} }

} // eo class SettingsForm

在上面的“示例”中,您可以使用字符串構(gòu)造一個SettingForm并獲取它可能使用的整數(shù)。在您的代碼中:


private void toolStripBtnSettings_Click(object sender, EventArgs e)

{

    PageInfoEventArgs args = new PageInfoEventArgs(SomeString);

    this.OnPageInfoRetrieved(args);


    SettingsForm settingsForm = new SettingsForm("some data to pass");

    settingsForm.ShowDialog();  


    int result = settingsForm.Example; // retrieve integer that SettingsForm used

}


查看完整回答
反對 回復 2019-12-06
?
長風秋雁

TA貢獻1757條經(jīng)驗 獲得超7個贊

結(jié)算表格是一個類?,F(xiàn)在是您的事了,您可以使用它來做自己喜歡的事。因此,向其構(gòu)造函數(shù)添加參數(shù)(或任意多個參數(shù))。然后在MainForm中調(diào)用SettingsForm(無論如何),就一切就緒。


查看完整回答
反對 回復 2019-12-06
  • 3 回答
  • 0 關(guān)注
  • 601 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號