最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C# ToolStrip制作四邊停靠浮動工具欄

 更新時間:2013年12月09日 11:57:50   作者:  
這篇文章主要介紹了C# ToolStrip浮動工具欄的制作,可以上/下/左/右???,代碼在下面

關(guān)于浮動工具條的制作,阿捷寫了一篇很不錯的文章,見:http://m.fzitv.net/article/44272.htm
阿捷這個工具條浮動后只能在頂部??浚诖?,我在這邊增加在左/右/底部??浚?織l件是浮動窗體緊貼或越過主窗體邊緣。

其實阿捷給出的代碼已經(jīng)相當詳細了:) 我這里主要給出重寫的ToolStrip代碼段,增加了三個ToolStripPanel

復(fù)制代碼 代碼如下:

    public partial class MyToolStrip : ToolStrip
    {
        public MyToolStrip()
        {
            InitializeComponent();
            this.EndDrag += new EventHandler(MyToolStrip_EndDrag);
            this.SizeChanged += new EventHandler(MyToolStrip_SizeChanged);
        }

        #region 漂浮狀態(tài)

        public ToolStripFloatWindow FloatWindow { get; set; }

        private bool isFloating
        {
            get
            {
                return (FloatWindow != null);
            }
        }

        public ToolStripPanel TopToolStripPanel { get; set; }
        public ToolStripPanel BottomToolStripPanel { get; set; }
        public ToolStripPanel LeftToolStripPanel { get; set; }
        public ToolStripPanel RightToolStripPanel { get; set; }

        #endregion

        #region 漂浮實現(xiàn)

        private void FloatWindow_LocationChanged(object sender, EventArgs e)
        {
            //當floatwindws的位置移動到 toolstrippanel中時,將this放置到 toolstripPanel上
            if (this.FloatWindow == null)
            {
                return;
            }
            if (FloatWindow.HasCreated)
            {
                //主窗體位置
                Point frmLoc = this.TopToolStripPanel.Parent.Location;
                //浮動工具條位置
                Point toolBarLoc = FloatWindow.Location;

                if (toolBarLoc.Y - frmLoc.Y <= 0) //置于頂部StripPanel
                {
                    this.FloatWindow.Controls.Remove(this);
                    this.TopToolStripPanel.SuspendLayout();
                    this.TopToolStripPanel.Controls.Add(this);
                    this.Location = this.TopToolStripPanel.PointToClient(toolBarLoc);
                    this.TopToolStripPanel.ResumeLayout();
                    this.FloatWindow.Dispose();
                    this.FloatWindow = null;
                    return;
                }
                if (toolBarLoc.X - frmLoc.X <= 0) //置于左邊StripPanel
                {
                    this.FloatWindow.Controls.Remove(this);
                    this.LeftToolStripPanel.SuspendLayout();
                    this.LeftToolStripPanel.Controls.Add(this);
                    this.Location = this.LeftToolStripPanel.PointToClient(toolBarLoc);
                    this.LeftToolStripPanel.ResumeLayout();
                    this.FloatWindow.Dispose();
                    this.FloatWindow = null;
                    return;
                }
                if (toolBarLoc.X + FloatWindow.Width >= this.TopToolStripPanel.Parent.Width) //置于右邊StripPanel
                {
                    this.FloatWindow.Controls.Remove(this);
                    this.RightToolStripPanel.SuspendLayout();
                    this.RightToolStripPanel.Controls.Add(this);
                    this.Location = this.RightToolStripPanel.PointToClient(toolBarLoc);
                    this.RightToolStripPanel.ResumeLayout();
                    this.FloatWindow.Dispose();
                    this.FloatWindow = null;
                    return;
                }
                if (toolBarLoc.Y + FloatWindow.Height >= this.TopToolStripPanel.Parent.Height) //置于底部StripPanel
                {
                    this.FloatWindow.Controls.Remove(this);
                    this.BottomToolStripPanel.SuspendLayout();
                    this.BottomToolStripPanel.Controls.Add(this);
                    this.Location = this.BottomToolStripPanel.PointToClient(toolBarLoc);
                    this.BottomToolStripPanel.ResumeLayout();
                    this.FloatWindow.Dispose();
                    this.FloatWindow = null;
                    return;
                }
            }
        }

        private void MyToolStrip_EndDrag(object sender, EventArgs e)
        {
            Point screenPt = Cursor.Position;
            Point clientPt = this.TopToolStripPanel.Parent.PointToClient(screenPt);

            //浮動區(qū)域
            Rectangle floatArea = new Rectangle(32, 32,    //我這里圖標大小調(diào)整為32*32
                this.TopToolStripPanel.Parent.Width - 2 * 32,
                this.TopToolStripPanel.Parent.Height - 2 * 32);

            if (floatArea.Contains(clientPt)) //判斷移出時
            {
                ToolStripFloatWindow fw = new ToolStripFloatWindow();
                fw.Controls.Add(this);
                this.Left = 0;
                this.Top = 0;
                this.FloatWindow = fw;
                FloatWindow.LocationChanged += new EventHandler(FloatWindow_LocationChanged);
                fw.SetBounds(screenPt.X, screenPt.Y, this.ClientSize.Width, this.ClientSize.Height + 22); //22為窗體標題欄高度
                  fw.Show();
             }
        }

        private void MyToolStrip_SizeChanged(object sender, EventArgs e)
        {
            if (this.isFloating)
            {
                this.FloatWindow.Width = this.ClientSize.Width;
            }
        }

        #endregion

    }

相關(guān)文章

  • C#之WinForm跨線程訪問控件實例

    C#之WinForm跨線程訪問控件實例

    這篇文章主要介紹了C#之WinForm跨線程訪問控件,實例講述了跨線程訪問控件的簡單實現(xiàn)方法與用法,需要的朋友可以參考下
    2014-10-10
  • C#生成漂亮驗證碼完整代碼類

    C#生成漂亮驗證碼完整代碼類

    本文主要介紹了C#生成漂亮驗證碼的完整代碼類。具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • C#中的協(xié)變與逆變方式

    C#中的協(xié)變與逆變方式

    協(xié)變和逆變是C#中處理泛型類型參數(shù)可變性的兩個重要概念,協(xié)變允許將派生類型的泛型參數(shù)轉(zhuǎn)換為基類型的泛型參數(shù),而逆變允許將基類型的泛型參數(shù)轉(zhuǎn)換為派生類型的泛型參數(shù),通過協(xié)變和逆變,可以提高代碼的靈活性和可重用性,但也需要注意類型參數(shù)的限制和安全性
    2024-12-12
  • c#中(&&,||)與(&,|)的區(qū)別詳解

    c#中(&&,||)與(&,|)的區(qū)別詳解

    這篇文章主要介紹了c#中(&&,||)與(&,|)的區(qū)別詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-12-12
  • C#多線程系列之線程池

    C#多線程系列之線程池

    本文詳細講解了C#多線程中的線程池,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-02-02
  • C#實現(xiàn)在匿名方法中捕獲外部變量的方法

    C#實現(xiàn)在匿名方法中捕獲外部變量的方法

    這篇文章主要介紹了C#實現(xiàn)在匿名方法中捕獲外部變量的方法,本文直接給出代碼實例,然后分析了代碼中的一些知識點,需要的朋友可以參考下
    2015-03-03
  • C# Winform實現(xiàn)捕獲窗體最小化、最大化、關(guān)閉按鈕事件的方法

    C# Winform實現(xiàn)捕獲窗體最小化、最大化、關(guān)閉按鈕事件的方法

    這篇文章主要介紹了C# Winform實現(xiàn)捕獲窗體最小化、最大化、關(guān)閉按鈕事件的方法,可通過重寫WndProc來實現(xiàn),需要的朋友可以參考下
    2014-08-08
  • C#中的委托、事件學習筆記

    C#中的委托、事件學習筆記

    這篇文章主要介紹了C#中的委托、事件學習筆記,本文講解了委托delegate、事件的相關(guān)知識并給出代碼實例,需要的朋友可以參考下
    2015-01-01
  • C#實現(xiàn)Winform監(jiān)控文件夾變化以及監(jiān)控文件操作教程

    C#實現(xiàn)Winform監(jiān)控文件夾變化以及監(jiān)控文件操作教程

    在開發(fā)應(yīng)用程序時,我們可能會因為場景的需要,要對文件系統(tǒng)中的文件或文件夾進行實時監(jiān)測,以便在文件內(nèi)容改變、文件被創(chuàng)建、刪除或重命名時能夠及時做出反應(yīng),今天,我將為大家介紹完整的操作流程,讓你輕松實現(xiàn)監(jiān)控文件/文件夾變化的功能,需要的朋友可以參考下
    2024-12-12
  • 一個C#開發(fā)者重溫C++的心路歷程

    一個C#開發(fā)者重溫C++的心路歷程

    作為一個C#開發(fā)為什么要重新學習C++呢?因為在C#在很多業(yè)務(wù)場景需要調(diào)用一些C++編寫的COM組件,如果不了解C++,那么,很容易。。。注定是要被C++同事忽悠的
    2019-05-05

最新評論

阿克陶县| 涞水县| 黔江区| 无锡市| 神池县| 长阳| 疏附县| 西盟| 安远县| 章丘市| 乐清市| 广安市| 肃北| 岳西县| 祁阳县| 淮安市| 琼海市| 山东省| 资源县| 阜宁县| 平邑县| 交口县| 沙湾县| 周宁县| 广汉市| 波密县| 华阴市| 绥江县| 扶余县| 任丘市| 枣阳市| 邯郸市| 墨江| 科尔| 黎川县| 灌阳县| 襄城县| 乐山市| 日喀则市| 丽江市| 浏阳市|