1

RichtTextBox を持つ新しい MDIChild を作成します。

Form myForm = new Form();
myForm.MdiParent = this;
RichTextBox rtb = new RichTextBox();
myForm.Controls.Add(rtb);
myForm.Show();

RTB を持たない他の MDIChild が開かれている可能性があるため、ActiveChild に RichtTextBox が含まれているかどうかを確認します。これを行う方法がわかりません... try-catch で次のようなもの (?):

foreach (Control control in this.ActiveMdiChild.Controls)
{
    // check if the control is a checkbox
    // make the richttextbox as an object so I can do strange things with it ^^
}

助けていただけませんか?

Thx & Cheers アレックス

4

1 に答える 1

0

演算子RichTextBoxを使用して、コントロールが a であるかどうかを確認できます。is

foreach (Control control in this.ActiveMdiChild.Controls)
{
    if (control is RichTextBox)
    {
        RichTextBox rtfChild = (RichTextBox)control;
        // From here on you can use rtfChild as any other RichTextBox control.
    }
}

もちろん、これを他のタイプのコントロールにも使用できます。

子フォームに があるかどうかを確認するにはRichTextBox:

bool found = false;
foreach (Control control in this.ActiveMdiChild.Controls)
{
    if (control is RichTextBox)
    {
        found = true;
        break;
    }
}

if (found)
{
}

これをRichTextBoxコントロールを返すメソッドに入れると、子フォームに があるかどうかをメソッドにチェックRichTextBoxさせ、ある場合はそれを返し、そうでない場合は返すことができnullます。

于 2013-03-20T14:43:26.383 に答える