您的位置:首页 > 编程语言 > C#

c#父窗体设置代码

2009-03-17 14:46 309 查看
 C#原代码

 最佳答案
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace wdemo6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
       

        private void 新窗体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Myform mf=new Myform();
            //设置父窗体为本窗体
            mf.MdiParent = this;
            //无模式窗体
            mf.Show();

            //模式窗体
            //mf.ShowDialog();           
        }

        private void 新窗体2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Myform mf = new Myform();
           
            Form2 f2 = new Form2();
            f2.Show();

            //设置父窗体为新产生的f2f
            mf.MdiParent = f2;
            mf.Show();

        }

        //子窗体4种排列方式
        private void 水平ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void 垂直ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileVertical);
        }

        private void 层叠ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.Cascade);
        }

        private void 一般ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void 选中窗体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form=this.ActiveMdiChild;
            if (form != null)
            {
                RichTextBox rtx = (RichTextBox)form.ActiveControl;
                rtx.Text = "这是当前选中窗体.";
            }
        }

        private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = this.ActiveMdiChild;
            if (form != null) {
                RichTextBox rtx = (RichTextBox)form.ActiveControl;
                Clipboard.SetDataObject(rtx.SelectedText);
            }
            else
            {
                MessageBox.Show("目前并未选中窗体");
            }

        }

        private void 粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = this.ActiveMdiChild;
            if (form != null)
            {
                RichTextBox rtx = (RichTextBox)form.ActiveControl;
                Clipboard.SetDataObject(rtx.Text);
            }
            else
            {
                MessageBox.Show("目前并未选中窗体");
            }
        }

        private void 全部复制ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form form = this.ActiveMdiChild;
            if (form != null)
            {
                RichTextBox rtx = (RichTextBox)form.ActiveControl;
                //Clipboard.GetDataObject().GetData(DataFormats.Text);
                rtx.Text = Clipboard.GetText();
                //Clipboard.SetDataObject(rtx.Text);
            }
            else
            {
                MessageBox.Show("目前并未选中窗体");
            }
        }

        private void 选项卡窗体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new Form3().Show();
        }
    }
}
**********************form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace wdemo6
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# object null class