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

C# ToolStrip制作四邊??扛?dòng)工具欄

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

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

其實(shí)阿捷給出的代碼已經(jīng)相當(dāng)詳細(xì)了:) 我這里主要給出重寫的ToolStrip代碼段,增加了三個(gè)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 漂浮實(shí)現(xiàn)

        private void FloatWindow_LocationChanged(object sender, EventArgs e)
        {
            //當(dāng)floatwindws的位置移動(dòng)到 toolstrippanel中時(shí),將this放置到 toolstripPanel上
            if (this.FloatWindow == null)
            {
                return;
            }
            if (FloatWindow.HasCreated)
            {
                //主窗體位置
                Point frmLoc = this.TopToolStripPanel.Parent.Location;
                //浮動(dòng)工具條位置
                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);

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

            if (floatArea.Contains(clientPt)) //判斷移出時(shí)
            {
                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為窗體標(biāo)題欄高度
                  fw.Show();
             }
        }

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

        #endregion

    }

相關(guān)文章

  • C#之WinForm跨線程訪問控件實(shí)例

    C#之WinForm跨線程訪問控件實(shí)例

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

    C#生成漂亮驗(yàn)證碼完整代碼類

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

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

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

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

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

    C#多線程系列之線程池

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

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

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

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

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

    C#中的委托、事件學(xué)習(xí)筆記

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

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

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

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

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

最新評(píng)論

临清市| 化隆| 会昌县| 岫岩| 杂多县| 普陀区| 南投市| 汽车| 电白县| 佛坪县| 长治市| 万盛区| 榆林市| 格尔木市| 秭归县| 离岛区| 宁城县| 龙门县| 伊通| 贵州省| 四子王旗| 武穴市| 曲水县| 微山县| 浠水县| 伊金霍洛旗| 阿坝| 商都县| 扎赉特旗| 新余市| 大厂| 杭锦后旗| 南和县| 大田县| 福贡县| 繁昌县| 韶关市| 高安市| 新安县| 泸西县| 宁陕县|