主要是想用C#在一个MDI程序中添加一个可以浮动的小窗口。
基本要求为:
1.类似于浮动工具栏,最好没有边框,可以任意拖动;
2.这个东西应该不是窗体,显示在所有窗体的最前面。
本来想用外接程序来实现,但是发现有点过于繁琐,还需要注册外接程序,想请大侠们帮帮指指路。用什么方式可以实现

解决方案 »

  1.   

    把窗体的样式设置一下就行了this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                this.MaximizeBox = false;
                this.MinimizeBox = false;
      

  2.   

    我有段代码,不知道是不是你想要的?
    要的话可以Mail给你!
      

  3.   

    //-------------------using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.MdiParent = this;
                f2.Show();
            }
        }
    }//-------------------------
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {
        public partial class Form2 : Form
        {
            bool IsMouseDown = false;        int x0 = 0;
            int y0 = 0;        public Form2()
            {
                InitializeComponent();            this.label1.Text = "你的控件摆在这里";
                this.label1.BackColor = Color.YellowGreen;            this.Width = 160;
                this.Height = 300;
                this.FormBorderStyle = FormBorderStyle.None;
                this.BackColor = Color.White;            this.MouseDown += new MouseEventHandler(Form2_MouseDown);
                this.MouseUp += new MouseEventHandler(Form2_MouseUp);
                this.MouseMove += new MouseEventHandler(Form2_MouseMove);
            }        void Form2_MouseMove(object sender, MouseEventArgs e)
            {
                if (IsMouseDown)
                {
                    this.Left += e.X -x0;
                    this.Top += e.Y -y0;
                }
            }        void Form2_MouseUp(object sender, MouseEventArgs e)
            {
                IsMouseDown = false;
            }        void Form2_MouseDown(object sender, MouseEventArgs e)
            {
                IsMouseDown = true;
                x0 = this.Left;
                y0 = this.Top;
            }
        }
    }
      

  4.   

    忘记加这个了  this.TopMost = true;
    补一下: public Form2()
            {
                InitializeComponent();            this.label1.Text = "你的控件摆在这里";
                this.label1.BackColor = Color.YellowGreen;            this.Width = 160;
                this.Height = 300;
                this.FormBorderStyle = FormBorderStyle.None;
                this.BackColor = Color.White;//新加的在这里
                this.TopMost = true;
    //新加的在这里            this.MouseDown += new MouseEventHandler(Form2_MouseDown);
                this.MouseUp += new MouseEventHandler(Form2_MouseUp);
                this.MouseMove += new MouseEventHandler(Form2_MouseMove);
            }
      

  5.   

    楼主将Form1的IsMdiChild设为true 就看到效果了
      

  6.   

    谢谢zoOoz,基本可以实现,只是你提供的void Form2_MouseDown(object sender, MouseEventArgs e) 中代码有少许错误。修改一下就可以了。再次感谢,散分,结贴。