DevComponents.DotNetBar2.dll设置样式的使用

本文介绍了一个具有项目流和工作流任务通知功能的消息盒子系统,通过定制化窗口展示任务详情,支持任务数量统计并提供关闭、显示、隐藏等交互操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有点模仿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();
                //    }
                //}
            }
        }


 

### 回答1: devcomponents.dotnetbar2.dll是一个用户界面控件库,它为开发人员提供了各种功能强大的控件和工具,用于创建各种Windows应用程序的界面。以下是该库的完整版使用教程: 1. 下载和安装:首先,从官方网站或其他可信的来源获取devcomponents.dotnetbar2.dll文件。然后,将它添加到你的项目中,并确保它包含在你的引用中。 2. 添加控件:在你的窗体或用户控件中,找到工具箱中的"DevComponents-组件"选项卡,并将你所需的控件从工具箱拖放到你的界面设计中。 3. 设置属性:选择你添加到界面中的每个控件,并在属性窗口中更改其属性,以满足你的需求。例如,你可以设置按钮的文本、大小、位置和样式。你还可以设置菜单、工具栏、标签等控件的属性。 4. 响应事件:为你的控件添加事件处理程序,以便在用户与之交互时执行特定的操作。例如,你可以为按钮的Click事件添加代码,执行某些任务。 5. 自定义样式:通过使用提供的主题和样式设计器,你可以为你的应用程序创建自定义的外观。在设计器中,你可以选择不同的主题、颜色和字体,以及更改控件的外观和行为。 6. 数据绑定:使用数据绑定功能,你可以将数据源与控件进行关联,实现动态显示和更新数据。你可以将数据库、XML文件、数据集或其他数据源绑定到控件上,以便在界面中显示数据。 7. 集成功能:devcomponents.dotnetbar2.dll还提供了一些额外的功能,例如弹出式提示、文本编辑器、表达式计算器等。你可以根据你的需求选择和使用这些功能。 8. 调试和优化:在完成界面设计和功能实现后,你应该对应用程序进行调试和优化。确保代码逻辑正确,并测试应用程序以确保其在不同的环境和情况下的稳定性和性能。 总结:通过遵循上述步骤,你可以使用devcomponents.dotnetbar2.dll完整版来创建各种丰富和功能强大的Windows应用程序界面。掌握这些步骤后,你将能够更有效地利用该库来满足你的界面需求。 ### 回答2devcomponents.dotnetbar2.dll 是一个用于开发 Windows 界面的控件库。它提供了丰富的界面组件和工具,能够帮助开发者快速构建美观、功能强大的应用程序。 要使用devcomponents.dotnetbar2.dll 完整版,需要按照以下步骤进行: 1. 下载和安装DLL文件:首先,从官方网站上下载devcomponents.dotnetbar2.dll 完整版。然后,将该DLL文件添加到你的项目中。 2. 添加命名空间:在你的代码文件的顶部,加入以下命名空间引用: ``` using DevComponents.DotNetBar; ``` 3. 实例化控件:在需要使用控件的窗体或用户控件中,实例化所需的控件对象。例如,要实例化一个按钮控件,可以使用以下代码: ``` ButtonX button = new ButtonX(); ``` 4. 设置控件的属性:根据需要,通过代码设置控件的各种属性,例如大小、位置、文本、颜色等。例如,要设置按钮的文本和背景颜色,可以使用以下代码: ``` button.Text = "点击我"; button.BackColor = Color.Red; ``` 5. 添加控件到容器:如果你的控件需要添加到一个容器中,例如面板或窗体,使用以下代码将控件添加到容器中: ``` panel.Controls.Add(button); ``` 6. 设置事件处理程序:根据需要,为控件的事件添加处理程序。例如,要为按钮控件添加单击事件处理程序,可以使用以下代码: ``` button.Click += Button_Click; ``` 7. 编写事件处理程序:在合适的地方编写事件处理程序的代码,以响应事件的发生。例如: ``` private void Button_Click(object sender, EventArgs e) { // 响应按钮的单击事件 MessageBox.Show("按钮被点击了!"); } ``` 通过以上步骤,你可以成功地使用devcomponents.dotnetbar2.dll 完整版来开发 Windows 应用程序。请注意,这只是一个简要的教程,你可能还需要参考官方文档或其他教程来了解更多详细的使用方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值