在 MDI中,通过父窗口操作子窗口中的一个RichTextBox,现在在一个父窗口中关联一个子窗口,然后在子窗口中加入了一个RichTextBox,现在想通过父窗口的菜单Undo来撤消richtextbox中输入的文字等。现在用this.ActiveMDIChild.richtextbox1.Undo();但是运行的时候说:System.Io.Form.Form中richtextbox1未定义错误 1 “System.Windows.Forms.Form”并不包含“richTextBox”的定义 E:\Project\C#\MDIBasic\MDIBasic\frmMail.cs 31 33 MDIBasic
这个是父窗口的代码 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace MDIBasic
{
    public partial class frmContainer : Form
    {
        public frmContainer()
        {
            InitializeComponent();
            this.IsMdiContainer = true;
            foreach (Control c in this.Controls)
            {
                if (c is MdiClient)
                {
                    c.BackColor = this.BackColor;
                    c.BackgroundImage = this.BackgroundImage;
                }
            }
            MDIBasic.frmChild child= new frmChild(this);
            child.Show();
        }        private void menuItemUndo_Click(object sender, EventArgs e)
        {
            this.ActiveMdiChild.richTextBox.Undo();
        }    }

解决方案 »

  1.   

    把你子窗体的richTextBox设为public,还要对ActiveMdiChild强制转换成你自己的窗体类型
      

  2.   

    (this.ActiveMDIChild as 你的子窗口类).richtextbox1.Undo();ActiveMDIChild返回是个Form基类
      

  3.   

    上面的各位大哥,能否说清楚点:
    txwd0033() :把你子窗体的richTextBox设为public,还要对ActiveMdiChild强制转换成你自己的窗体类型    这个我也设置成public了
    现在代码 :(frmChild)(this.ActiveMdiChild).richTextBox1.Undo();这样也错。
      

  4.   

    ((frmChild)(this.ActiveMdiChild)).richTextBox1.Undo();改成这样现在出现错误说没有创建对象
      

  5.   

    if (this.ActiveMdiChild.ActiveControl is RichTextBox)
      (this.ActiveMdiChild.ActiveControl as RichTextBox).Undo();