• 大小: 82KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: C#
  • 标签:

资源简介

实现了一个可以拖拽的工具栏,自动停靠。 使用方法 1、首先要在窗口上创建一个ToolStripPanel 2、然后直接将FloatToolstrip拖放到窗口上,放在ToolStripPanel上 3、设置FloatToolstrip的ToolStripPanel属性为第一步创建的ToolStripPanel 就以运行了!

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace FloatToolStripDemo
{
    public partial class FloatToolstrip : ToolStrip
    {
        private ToolStripPanel tsPanel;

        public FloatToolstrip()
        {
            InitializeComponent();
            this.EndDrag += new EventHandler(MyToolStrip_EndDrag);
            this.SizeChanged += new EventHandler(MyToolStrip_SizeChanged);
        }

        private ToolStripFloatWindow floatForm;
        public ToolStripFloatWindow FloatForm
        {
            get { return floatForm; }
            set
            {
                floatForm = value;
                if (floatForm != null)
                {
                    floatForm.Locationchanged += new EventHandler(floatForm_Locationchanged);
                    floatForm.FormClosing += new FormClosingEventHandler(floatForm_FormClosing);
                }
            }
        }

        void floatForm_FormClosing(object sender FormClosingEventArgs e)
        {
            e.Cancel = true;
        }

        private void floatForm_Locationchanged(object sender EventArgs e)
        {
            //当floatwindws的位置移动到toolstrippanel中时,将this放置到 toolstripPanel上  
            if (this.floatForm == null)
            {
                return;
            }
            else
            {
                if (floatForm.HasCreated)
                {
                    Point currentPt = new Point(floatForm.Location.X floatForm.Location.Y);
                    Point minPt = this.tsPanel.PointToScreen(tsPanel.Location);
                    Point maxPt;
                    if (this.tsPanel.Height <= 20)
                    {
                        maxPt = new Point(minPt.X + this.tsPanel.Width minPt.Y + 20);

                    }
                    else
                    {
                        maxPt = new Point(minPt.X + this.tsPanel.Width minPt.Y + this.tsPanel.Height);
                    }

                    if ((currentPt.X > minPt.X) && (currentPt.X < maxPt.X) && (currentPt.Y > minPt.Y - 25) && (currentPt.Y < maxPt.Y - 25))
                    {
                        this.floatForm.Controls.Remove(this);
                        this.tsPanel.SuspendLayout();
                        this.tsPanel.Controls.Add(this);
                        this.Location = this.tsPanel.PointToClient(currentPt);
                        this.tsPanel.ResumeLayout();
                        this.floatForm.Dispose();
                        this.floatForm = null;
                    }
                }
            }
        }

        public bool isFloating
        {
            get
            {
                return (floatForm != null);
            }
        }

        public ToolStripPanel ToolStripPanel
        {
            get
            {

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\
     目录           0  2010-04-23 17:49  FloatToolStripDemo\FloatToolStripDemo\bin\
     目录           0  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\bin\Debug\
     文件       14848  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\bin\Debug\FloatToolStripDemo.exe
     文件       32256  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\bin\Debug\FloatToolStripDemo.pdb
     文件       14328  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\bin\Debug\FloatToolStripDemo.vshost.exe
     文件         490  2007-07-21 01:33  FloatToolStripDemo\FloatToolStripDemo\bin\Debug\FloatToolStripDemo.vshost.exe.manifest
     文件        4528  2010-04-23 17:35  FloatToolStripDemo\FloatToolStripDemo\FloatToolstrip.cs
     文件        1112  2010-04-23 17:07  FloatToolStripDemo\FloatToolStripDemo\FloatToolstrip.Designer.cs
     文件        3598  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\FloatToolStripDemo.csproj
     文件         348  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\Form1.cs
     文件        7681  2010-04-23 17:35  FloatToolStripDemo\FloatToolStripDemo\Form1.Designer.cs
     文件       12168  2010-04-23 17:35  FloatToolStripDemo\FloatToolStripDemo\Form1.resx
     目录           0  2010-04-23 15:51  FloatToolStripDemo\FloatToolStripDemo\obj\
     目录           0  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\
     文件        1135  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\FloatToolStripDemo.csproj.FileListAbsolute.txt
     文件         921  2010-04-23 17:48  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\FloatToolStripDemo.csproj.GenerateResource.Cache
     文件       14848  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\FloatToolStripDemo.exe
     文件        4654  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\FloatToolStripDemo.Form1.resources
     文件       32256  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\FloatToolStripDemo.pdb
     文件         180  2010-04-23 17:50  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\FloatToolStripDemo.Properties.Resources.resources
     文件         180  2010-04-23 17:40  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\FloatToolStripDemo.ToolStripFloatWindow.resources
     目录           0  2010-04-23 17:10  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\Refactor\
     目录           0  2010-04-23 15:51  FloatToolStripDemo\FloatToolStripDemo\obj\Debug\TempPE\
     文件         479  2010-04-23 17:32  FloatToolStripDemo\FloatToolStripDemo\Program.cs
     目录           0  2010-04-23 15:51  FloatToolStripDemo\FloatToolStripDemo\Properties\
     文件        1380  2010-04-23 15:51  FloatToolStripDemo\FloatToolStripDemo\Properties\AssemblyInfo.cs
     文件        2886  2010-04-23 15:51  FloatToolStripDemo\FloatToolStripDemo\Properties\Resources.Designer.cs
     文件        5612  2010-04-23 15:51  FloatToolStripDemo\FloatToolStripDemo\Properties\Resources.resx
     文件        1103  2010-04-23 15:51  FloatToolStripDemo\FloatToolStripDemo\Properties\Settings.Designer.cs
     文件         249  2010-04-23 15:51  FloatToolStripDemo\FloatToolStripDemo\Properties\Settings.settings
............此处省略28个文件信息

评论

共有 条评论

相关资源