happyqiang

博客园 首页 新随笔 联系 订阅 管理

cad2015+版本可以使用TrayItem气泡显示消息

   static TrayItem trayItem = new TrayItem();
        public static void testtrayitem()
        {
            try
            {

                //新建一个气泡通知窗口
                TrayItemBubbleWindow window = new TrayItemBubbleWindow();
                window.Title = "气泡标题";
                window.HyperText = "气泡内容连接";
                window.Text = "气泡内容";
                window.IconType = IconType.Information;

                Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.TrayItems.Add(trayItem);
                trayItem.ShowBubbleWindow(window);
                Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.Update();
                //气泡窗口关闭事件
                //window.Closed += (sender, e) =>
                //{
                //    if (e.CloseReason == TrayItemBubbleWindowCloseReason.HyperlinkClicked)
                //    {
                //        System.Windows.MessageBox.Show("关闭气泡消息");

                //    }
                //    //气泡窗口关闭后,将托盘从状态栏删除
                //    //Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.TrayItems.Remove(trayItem);
                //    //Autodesk.AutoCAD.ApplicationServices.Application.StatusBar.Update();
                //};
                System.Timers.Timer t = new System.Timers.Timer(10000);
                t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_ChangePos);//到达时间的时候执行事件;                  
                t.AutoReset = false;//设置是执行一次(false)还是一直执行(true);                
                t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
            }
            catch (System.Exception ex)
            {
                trayItem.CloseBubbleWindows();
            }

        }
        private static void Timer_ChangePos(object sender, System.Timers.ElapsedEventArgs e)
        {
            trayItem.CloseBubbleWindows();
        }

  cad2010+mq+dotnetbar的 DevComponents.DotNetBar.Balloon窗体:

IExtensionApplication接口下:

//为了能及时接收消息
RabbitMQClient mq = new RabbitMQClient();

  public  class RabbitMQClient
    {
        private string exchangeName = "topic_logs"; //
        private string exchangeType = ExchangeType.Topic;//交换机类型
        Action<string, Form> SetText;
        public RabbitMQClient()
        {
            if (CommandFun.frmmsg==null)
            {
                CommandFun.frmmsg = new FrmMsg();
            }
            ReceiveMsg(CommandFun.frmmsg);
            SetText += CommandFun.ShowLoadAlert;
        }
        public  void ReceiveMsg(Form frm)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "iporlocalhost",
                Port = 端口,
                UserName = "administrator",
                Password = "密码"
            };
            try
            {

                var connection = factory.CreateConnection();
                var channel = connection.CreateModel();

                channel.ExchangeDeclare(exchangeName, exchangeType);
                var queueName = channel.QueueDeclare().QueueName;


                    channel.QueueBind(queueName, exchangeName, "*.*.two");
                    channel.QueueBind(queueName, exchangeName, "two.#");

                var consumer = new EventingBasicConsumer(channel);
                consumer.Received += (model, ea) =>
                {
                    var msg = Encoding.UTF8.GetString(ea.Body);
                    if (msg!=null && msg.ToString().Length>0)
                    {
                        if (frm == null)
                        {
                            frm =CommandFun.frmmsg;
                        }
                        frm.Invoke(SetText, msg, frm);
                    }
                };
                channel.BasicConsume(queueName, true, consumer);
            }
            catch (System.Exception ex)
            {

            }
        }
    }
View Code

 

接收到消息时调用方法show出窗体:
   public class CommandFun
    {
       public static FrmMsg frmmsg;//接收到消息
       //弹出右下角消息窗口
       public static void ShowLoadAlert(string msg, System.Windows.Forms.Form frmmsg)
       {
           FrmMsg m_AlertOnLoad = new FrmMsg();
           Rectangle r = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;// GetWorkingArea(this);
           m_AlertOnLoad.Location = new Point(r.Right - m_AlertOnLoad.Width, r.Bottom - m_AlertOnLoad.Height);
           m_AlertOnLoad.AutoClose = true;
           m_AlertOnLoad.AutoCloseTimeOut = 60;
           m_AlertOnLoad.AlertAnimation = eAlertAnimation.BottomToTop;
           m_AlertOnLoad.AlertAnimationDuration = 2000;
           m_AlertOnLoad.SetLableText(msg);
           m_AlertOnLoad.Show(false);
       }

     
    }
CommandFun

窗体:

  public partial class FrmMsg : DevComponents.DotNetBar.Balloon
    {
        public FrmMsg()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }

        public void SetLableText(string msg)
        {
            lbl_msg.Text = string.Format("{0}\r\n", msg);
        }
    }
FrmMsg

 

posted on 2019-04-29 16:40  妙堂传奇  阅读(297)  评论(0编辑  收藏  举报