首页 技术 正文
技术 2022年11月15日
0 收藏 341 点赞 2,674 浏览 3150 个字

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>)
{
if (frm == null)
{
frm =CommandFun.frmmsg;
}
frm.Invoke(SetText, msg, frm);
}
};
channel.BasicConsume(queueName, true, consumer);
}
catch (System.Exception ex)
{ }
}
}

接收到消息时调用方法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 = ;
m_AlertOnLoad.AlertAnimation = eAlertAnimation.BottomToTop;
m_AlertOnLoad.AlertAnimationDuration = ;
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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,496
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,909
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,743
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,496
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,134
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298