DevComponents.DotNetBar2.dll設置樣式的使用

有點模仿QQ消息盒子的感覺,代碼如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using DevComponents.DotNetBar;


namespace BW_ArasSpirit
{
    public partial class SystemMsgBox : Form
    {
        private static SystemMsgBox _initialize = null;

        public static SystemMsgBox getinstance()
        {
            if (_initialize == null)
            {
                _initialize = new SystemMsgBox();
            }
            return _initialize;
        }

        #region 變量
        private bool boolVisible = false;
        #endregion

        #region 拖動無邊框窗體
        [DllImport("user32.dll")]//*********************拖動無窗體的控件
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;
        #endregion

        public SystemMsgBox()
        {
            InitializeComponent();
        }

        //#region 鼠標Move Hover Leave樣式區域
        //private void labelShowMsg_MouseMove(object sender, MouseEventArgs e)
        //{
        //    labelShowMsg.ForeColor = Color.FromArgb(50, 50, 50);
        //}

        //private void labelShowMsg_MouseLeave(object sender, EventArgs e)
        //{
        //    labelShowMsg.ForeColor = Color.FromArgb(100, 100, 100);
        //}
        //#endregion

        #region 取消窗體關閉事件
        private void FormMessage_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            boolVisible = true;
            timerShowWindow.Enabled = true;
            timerWait.Enabled = false;
        }
        #endregion

        #region 窗體關閉
        private void btnFormClose_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Close();
            }
        }
        #endregion

        #region 顯示窗體函數
        public void ShowWindow(List<Task> wlplist,List<Task> ptasklist)
        {
            this.Show();
            this.Opacity = 0;
            boolVisible = false;
            timerWait.Interval = 5000;
            Point point;
            try
            {
                point = frmSet.point;
            }
            catch (Exception e)
            {
                throw e;
            }
            this.Location = new Point((((point.X+10) + (point.X -10))/2)- (this.Size.Width/2), Screen.PrimaryScreen.Bounds.Height - 40 - this.Size.Height);
            timerShowWindow.Enabled = true;
            int wlpcount = wlplist.Count;
            int pacount = ptasklist.Count;
            if (wlpcount == 0)
            {
                lbltasklist.Text = "項目流任務-" + ptasklist[0].Ptaskname + "  (" + ptasklist.Count + ")";
                labelXTitle.Text ="消息盒子"+"  ("+"1"+")";
            }
            if (pacount == 0)
            {
                lblwlplist.Text = "工作流任務-" + wlplist[0].Wlptaskname + "  (" + wlplist.Count + ")";
                labelXTitle.Text = "消息盒子" + "  (" + "1" + ")";
            }
            if (wlpcount != 0 && pacount != 0)
            {
                lbltasklist.Text = "項目流任務-" + ptasklist[0].Ptaskname + "  (" + ptasklist.Count + ")";
                lblwlplist.Text = "工作流任務-" + wlplist[0].Wlptaskname + "  (" + wlplist.Count + ")";
                labelXTitle.Text = "消息盒子" + "  (" + "2" + ")";
            }
        }
        #endregion

        #region 控制窗體顯示
        private void timerShowWindow_Tick(object sender, EventArgs e)
        {
            if (!boolVisible)
            {
                this.Opacity += 0.1;
                if (this.Opacity >= 1)
                {
                    timerShowWindow.Enabled = false;
                    timerWait.Enabled = false;
                    boolVisible = false;
                }
            }
            else
            {
                this.Opacity -= 0.1;
                if (this.Opacity == 0)
                {
                    boolVisible = false;
                    this.Hide();
                    timerShowWindow.Enabled = false;
                    timerWait.Enabled = false;
                }
            }
        }
        #endregion    

        #region 等待
        private void timerWait_Tick(object sender, EventArgs e)
        {
            timerShowWindow.Enabled = false;
            timerWait.Enabled = false;
        }
        #endregion

        #region 移動無邊框窗體事件
        private void labelXTitle_MouseDown(object sender, MouseEventArgs e)
        {
            //ReleaseCapture();
            //SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);//*********************調用移動無窗體控件函數
        }
        #endregion

        public delegate void MyDelegate(bool istrue);
        public event MyDelegate MyEvent;
        private void label1_Click(object sender, EventArgs e)
        {
            try
            {
                MyEvent(true);
                this.Hide();
            }
            catch (Exception exp)
            {           
                throw exp;
            }        
        }

        public static bool istrueexit = false;
        private void SystemMsgBox_Load(object sender, EventArgs e)
        {
           
        }

        //private void labelXTitle_MouseMove(object sender, MouseEventArgs e)
        //{
        //    labelXTitle.ForeColor = Color.Red;
        //    labelXTitle.Font = new Font(labelXTitle.Font, FontStyle.Bold | FontStyle.Underline);
        //}

        //private void labelXTitle_MouseLeave(object sender, EventArgs e)
        //{
        //    labelXTitle.ForeColor = Color.White;
        //    labelXTitle.Font = new Font(labelXTitle.Font, FontStyle.Bold);
        //}
    }
}

mian.cs

public SystemMsgBox smb = SystemMsgBox.getinstance();
        private void niIcon_MouseDown(object sender, MouseEventArgs e)
        {
            if (isRun && IsCloseWindow == "0")
            {
                point = Cursor.Position;
                if (!smb.Visible)
                {
                    smb.MyEvent +=new SystemMsgBox.MyDelegate(this.getreturnvalue);
                    smb.ShowWindow(wlptasklist,ptasklist);
                    timerpoint.Start();
                }
            }
        }

 private Point lastpoint;
        private void timerpoint_Tick(object sender, EventArgs e)
        {
            if (lastpoint == null) return;
            if (smb.Visible)
            {
                //定義範圍
                //起始位置
                lastpoint = Cursor.Position;
                if (lastpoint.Y > point.Y + 100 || lastpoint.Y < point.Y - 100)
                {
                    //超出高度隱藏
                    smb.Hide();
                    timerpoint.Stop();
                }
                //根據y的範圍判定x的取值
                int x = (((point.X + 10) + (point.X - 10)) / 2) - (211 / 2);
                int y = Screen.PrimaryScreen.Bounds.Height - 40 - 97;

                //圖標的上方,判斷窗體的範圍
                if (lastpoint.Y < y || lastpoint.Y != y)
                {
                    if (lastpoint.X < x || lastpoint.X > x + 211)
                    {
                        smb.Hide();
                    }
                }
                //圖標的下方,判斷圖標的範圍
                //if (lastpoint.Y > y || lastpoint.Y != y)
                //{
                //    if (lastpoint.X < x + 211 / 2 - 10 || lastpoint.X > x + 211 / 2 + 10)
                //    {
                //        smb.Hide();
                //    }
                //}
            }
        }


 

發佈了27 篇原創文章 · 獲贊 4 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章