簡體   English   中英

給定條件打開另一個表格? C#視覺工作室

[英]Open another form given a condition? C# visual studio

我在名為“Suscripciones”的form1中,我想調用名為“Suscripcion”的form2。 我會顯示代碼...

 DialogResult dialog = MessageBox.Show("You want to add a new suscriptor?", "Suscripcion",
                MessageBoxButtons.YesNo);

                if (dialog == DialogResult.Yes)
                {
                    Form sus = new Suscripcion();
                    sus.Show();
                }

但這給了我 Suscripciones(); 的錯誤。 錯誤消息表明:“沒有給出與所需形式參數相對應的參數”我不知道該怎么做,我無法調用其他形式。

這是將參數從一個 winform 傳遞到另一個窗體的基本方法。

在form1點擊事件中添加

private void button1_Click(object sender, EventArgs e)
{
    Form1 newform = new Form1();
    newform = this;
    this.Hide();
    MySecform = new Form2(ref newform);
    MySecform.Show();
}

在 form2 構造函數中

public Form2(ref Form1 form1handel)
{
    firstformRef = form1handel;
    InitializeComponent();
}

在 form2 crate 變量Form1 firstformRef;

private void Submitt_Click(object sender, EventArgs e)
{
    firstformRef.TextBoxString = textBox1.Text;
    this.Close();
    firstformRef.Show();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM