2011-07-18 49 views
0

我有windows-mobile程序有2種形式。如何發送點擊從窗體到窗體

在form1中,我有TextBox和form2中,我有5個按鈕。

怎麼做,當我按在窗口2我會看到他們的文本框,在Form1中

回答

1

創建窗體上的公共財產,這將允許調用的形式訪問選擇的值的按鈕。

public partial class SelectionForm : Form 
{ 
    public SelectionForm() 
    { 
     InitializeComponent(); 
    } 

    //Selection holder 
    private string _selection; 

    //Public access to this item 
    public string Selection { get { return _selection; } } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     _selection = "One was selected"; 
     this.Close(); 
    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     _selection = "Two was selected"; 
     this.Close(); 
    } 
} 

然後從您的調用表單中,您可以在表單處理之前獲取此值。

public partial class TextForm : Form 
{ 
    public TextForm() 
    { 
     InitializeComponent(); 
    } 

    private void btnSelect_Click(object sender, EventArgs e) 
    { 
     using (SelectionForm selectionForm = new SelectionForm()) 
     { 
      selectionForm.ShowDialog(); 
      txtSelection.Text = selectionForm.Selection; 
     } 
    } 
}