欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

關(guān)于浮動(dòng)工具條的制作,阿捷寫了一篇很不錯(cuò)的文章,見:http://www.dbjr.com.cn/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#實(shí)現(xiàn)把圖片轉(zhuǎn)換成二進(jìn)制以及把二進(jìn)制轉(zhuǎn)換成圖片的方法示例

    C#實(shí)現(xiàn)把圖片轉(zhuǎn)換成二進(jìn)制以及把二進(jìn)制轉(zhuǎn)換成圖片的方法示例

    這篇文章主要介紹了C#實(shí)現(xiàn)把圖片轉(zhuǎn)換成二進(jìn)制以及把二進(jìn)制轉(zhuǎn)換成圖片的方法,結(jié)合具體實(shí)例形式分析了基于C#的圖片與二進(jìn)制相互轉(zhuǎn)換以及圖片保存到數(shù)據(jù)庫(kù)的相關(guān)操作技巧,需要的朋友可以參考下
    2017-06-06
  • C#初始化數(shù)組的方法小結(jié)

    C#初始化數(shù)組的方法小結(jié)

    這篇文章主要介紹了C#初始化數(shù)組的方法,總結(jié)分析了C#聲明與初始化一維數(shù)組及多維數(shù)組的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2016-06-06
  • 在C#中新手易犯的典型缺陷

    在C#中新手易犯的典型缺陷

    這篇文章的主要內(nèi)容是關(guān)于C#那些新手易犯的典型缺陷,只有對(duì)有可能犯的錯(cuò)誤進(jìn)行總結(jié)才能做得更好,需要的朋友可以參考下
    2015-07-07
  • C#遞歸算法之打靶算法分析

    C#遞歸算法之打靶算法分析

    這篇文章是對(duì)打靶算法分析,比較簡(jiǎn)單,但邏輯一定要清楚,分析問題的方法一定要準(zhǔn)確,有需要的朋友可以參考一下。
    2016-06-06
  • c# 文件壓縮zip或?qū)ip文件解壓的方法

    c# 文件壓縮zip或?qū)ip文件解壓的方法

    下面小編就為大家分享一篇c# 文件壓縮zip或?qū)ip文件解壓的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧
    2018-03-03
  • WPF如何自定義TabControl控件樣式示例詳解

    WPF如何自定義TabControl控件樣式示例詳解

    這篇文章主要給大家介紹了關(guān)于WPF如何自定義TabControl控件樣式的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • c#消息提示框messagebox的詳解及使用

    c#消息提示框messagebox的詳解及使用

    這篇文章主要介紹了c#消息提示框messagebox的詳解及使用的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • 詳解c# 協(xié)變和逆變

    詳解c# 協(xié)變和逆變

    這篇文章主要介紹了c# 協(xié)變和逆變的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)c#,感興趣的朋友可以了解下
    2020-11-11
  • C#?Math中常用數(shù)學(xué)運(yùn)算的示例詳解

    C#?Math中常用數(shù)學(xué)運(yùn)算的示例詳解

    Math?為通用數(shù)學(xué)函數(shù)、對(duì)數(shù)函數(shù)、三角函數(shù)等提供常數(shù)和靜態(tài)方法,使用起來(lái)非常方便。這篇文章主要為大家介紹幾個(gè)常用的數(shù)學(xué)運(yùn)算的使用,需要的可以參考一下
    2022-11-11
  • DevExpress SplitContainerControl用法總結(jié)

    DevExpress SplitContainerControl用法總結(jié)

    這篇文章主要介紹了DevExpress SplitContainerControl用法,對(duì)初學(xué)者有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2014-08-08

最新評(píng)論