2011-09-16 9 views
1

私のコード:parent_Formでどのように子供のwinformによって親winformのstatustipを処理するのですか?

:子フォームで

public parent_Form() 
    { 
     InitializeComponent(); 
    } 

    private void button_Click(object sender, EventArgs e) 
    { 
     child ch = new child(); 
     ch.MdiParent = this; 
     ch.Show(); 
    } 
    public string label 
    { 
     set 
     { 
      textBox1.Text = value; 
     } 
    } 

public child() 
    { 
     InitializeComponent(); 
    } 

    private void write_button_Click(object sender, EventArgs e) 
    { 
     parent_Form paren = new parent_Form(); 
     paren.label = "i am vietnamese"; 
    } 

しかし "私はベトナムだ"(TextBox1テキストボックスに表示されません。親winform上にある)

答えて

0

JRoughanの解決策が必要です。ボタンクリックハンドラが正しく指定されていることを確認してください。ハンドラにブレークポイントを設定して、ボタンをクリックしたときにハンドラが実行されていることを確認します。私はこれを試して、それは動作します。

public child() 
{ 
    InitializeComponent(); 
} 

private void write_button_Click(object sender, EventArgs e) 
{ 
    parent_Form paren = ((parent_Form)MdiParent); 
    paren.label = "i am vietnamese"; 
} 
+0

ありがとうございました。とても役に立ちます – rocket42

2

このライン:

parent_Form paren = new parent_Form(); 

が示されることはありません新しいparent_Formを作成しています。実際の親を参照する必要があります。

((parent_Form)MdiParent).label = "i am vietnamese"; 
関連する問題