類似於FlashGet,迅雷一樣的懸浮視窗

來源:互聯網
上載者:User
第一部分 :

經常會看到類似FlashGet和迅雷這樣的下載工具,當最小化時,螢幕右上方會出現一個懸浮視窗,可以用滑鼠拖動到任何位置,滑鼠右鍵可以做一些操作,滑鼠移上去的時候下面也會有提示,那麼這些用C#是如何?的哪?

第一,懸浮視窗是一個TopMost表單(建立表單,設定TopMost屬性);
第二,滑鼠拖動,做拖動就是要對TopMost表單添加一個MouseMove事件,判斷滑鼠的位置,通過改變Location移動TopMost表單;
第三,滑鼠右鍵,在 .net 2.0裡可以對TopMost表單添加ContextMenuStrip來實現;
第四,跟隨滑鼠的提示,可以對表單添加ToolTip組件;ToolTip有3個主要的延遲屬性:InitialDelay (多長時間工具提示字串才會出現)、ReshowDelay(移到另一個控制項時,出現後面的工具提示字串所需的毫秒數)、AutoPopDelay(提示字串顯示多長時間),在表單上可以設定這些屬性。不過MS做的這個組件似乎有點問題,如果移動了表單,那麼ToolTip就再也不會出現提示,還有就是如果AutoPopDelay=5000;那麼5秒之後提示框自動消失,並且以後再也不會出現提示,但是如果你是在<5秒時手動移開了滑鼠,那麼才正常;為了避免這種情況,可以給TopMost表單添加兩個事件:frmTopMost_MouseEnter 和frmTopMost_MouseLeave:        private void frmTopMost_MouseEnter(object sender, System.EventArgs e)
        {
            this.toolTip1.Active = true;
            this.toolTip1.AutoPopDelay = 5000;
            this.toolTip1.InitialDelay = 500;
            this.toolTip1.ReshowDelay = 100;
            this.toolTip1.ShowAlways = true;
        }

        private void frmTopMost_MouseLeave(object sender, System.EventArgs e)
        {
            this.toolTip1.Active = false;
        }

這樣就正常了。

第二部分 部分代碼

滑鼠拖動表單
private void frmTopMost_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (blnMouseDown)
            {
                //Get the current postion of the mouse in the screen.
                ptMouseNewPos = Control.MousePosition;

                //Set window postion.
                ptFormNewPos.X = ptMouseNewPos.X - ptMouseCurrentPos.X + ptFormPos.X;
                ptFormNewPos.Y = ptMouseNewPos.Y - ptMouseCurrentPos.Y + ptFormPos.Y;

                //Save window postion.
                Location = ptFormNewPos;
                ptFormPos = ptFormNewPos;

                //Save mouse pontion.
                ptMouseCurrentPos = ptMouseNewPos;
            }
        }

第三部分

Source  DownLoad

Exe files:http://files.cnblogs.com/Roger52027/TopMost.rar
Solution files:http://files.cnblogs.com/Roger52027/TopMostSolution.rar

註:此文章是參考愚翁大哥的一篇文章而寫的。地址:http://blog.csdn.net/Knight94

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.