rt,不适用MDI方式。

解决方案 »

  1.   

    subform.toplevel=false;
    parentform.controls.add(subform);
    subform.show();
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;namespace WindowsApplication92
    {
        public partial class Form1 : Form
        {        [DllImport("user32.dll")]
            public static extern int SetParent(int hWndChild, int hWndNewParent);        public Form1()
            {
                InitializeComponent();            Form F = new Form();
                F.Show();
                SetParent(F.Handle.ToInt32(), this.Handle.ToInt32());
            }
        }
    }
      

  3.   

    将主窗体的TRect传入子窗体,或者为子窗体自定父窗体,在子窗体的LocationChanged事件中判断边界是否超出了主窗体的范围
      

  4.   


    private void button1_Click(object sender, EventArgs e)
    {
        Form2 frm = new Form2();
        frm.TopLevel = false;
        this.Controls.Add(frm);
        frm.Show();
    }
      

  5.   

    wartim您好,如果按您的方式,怎么能够让窗体出现滚动条?因为我把子窗体移动到外面的话不会出现滚动条
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;namespace WindowsFormsApplication56
    {
        public partial class Form1 : Form
        {        [DllImport("user32.dll")]
            public static extern int SetParent(int hWndChild, int hWndNewParent);        Form F = null;        public Form1()
            {
                InitializeComponent();            F = new Form();
                F.Show();
                SetParent(F.Handle.ToInt32(), this.Handle.ToInt32());            F.LocationChanged += new EventHandler(F_LocationChanged);
                this.Resize += new EventHandler(Form1_Resize);            this.Scroll += new ScrollEventHandler(Form1_Scroll);
            }        void Form1_Resize(object sender, EventArgs e)
            {
                SetScroll(F);
            }        void F_LocationChanged(object sender, EventArgs e)
            {
                SetScroll(F);
            }        void SetScroll(Form F)
            {
                Point P = this.PointToClient(F.Location);            this.HorizontalScroll.Maximum = (P.X + F.Width) / this.Width * 10;
                this.HorizontalScroll.Value = 0;
                this.VerticalScroll.Maximum = (P.Y + F.Height) / this.Height * 10;
                this.VerticalScroll.Value = 0;            int VerticalScrollWidth = this.VerticalScroll.Maximum > 0 ? 20 : 0;
                int HorizontalScrollWidth = this.HorizontalScroll.Maximum > 0 ? 20 : 0;            this.HorizontalScroll.Visible = (P.X + F.Width + VerticalScrollWidth) > this.Width;
                this.VerticalScroll.Visible = (P.Y + F.Height + HorizontalScrollWidth) > this.Height;
            }        void Form1_Scroll(object sender, ScrollEventArgs e)
            {
                // ..... 
            }
        }
    }
      

  7.   

    VerticalScroll 还要多加一个标题栏高度
      

  8.   

    2楼的方法比4楼的多实现什么功能了? (4楼的方法不是MDI的)为什么绕远用 DllImport? 纯技术讨论,楼主解释一下。 
      

  9.   

    滚动条是FORM本身的功能.
    this.AutoScroll = true;