• RichTextBox与NotifyIcon简单模仿QQ效果


    RichTextBox简单实现,消息时间为颜色显示

     

    private void recv_msg_Click(object sender, EventArgs e)
            {
                RecvText.SelectionStart 
    = RecvText.Text.Length;
                RecvText.SelectionColor 
    = Color.Blue;
                RecvText.AppendText(DateTime.Now.ToString() 
    + "\r\n");
                RecvText.AppendText(
    "how are you\r");
            }

    private void send_msg_Click(object sender, EventArgs e)
            {
                
    if(SendText.Text!="")
                {
                    RecvText.SelectionStart 
    = RecvText.Text.Length;
                    RecvText.SelectionColor 
    = Color.Red;
                    RecvText.AppendText(DateTime.Now.ToString() 
    + "\r\n");
                    RecvText.AppendText(SendText.Text
    +"\r");
                }
            }

    非常简单,只需要在插入消息时间之前将光标移动到RichTextBox末尾,并设置选中内容的颜色为所需颜色,实际上添加的新行自动成为了选中内容SelectedText

    2,NotifyIcon闪烁

         需要2张ICO图片,16*16 一张为显示的托盘图标,另一张为透明的空图标,添加到资源中

         添加一个Timer 间隔 500毫秒,Timer_Tick时间中变换NotifyIcon控件的ICO属性图标

        int ico_index = 0;

            private void NotofyTimer_Tick(object sender, EventArgs e)
            {
                Icon ico 
    = (ico_index==1? Properties.Resources.ico0 : Properties.Resources.ico1;
                ico_index 
    = (ico_index == 1? 0 : 1;
                MainNotify.Icon
    =ico;
            }

    //双击闪烁图标
    private void MainNotify_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                NotofyTimer.Stop();
                MainNotify.Icon 
    = Properties.Resources.ico0;
                
    using(frmMessage frm=new frmMessage())
                {
                    frm.ShowDialog();
                }
            }
    //开始Timer模拟闪烁图标
            private void START_TIMER_MENU_Click(object sender, EventArgs e)
            {
                NotofyTimer.Start();
            }

      为了消除程序关闭后托盘图标,在窗体Closeing时间中执行

     private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
            {
                MainNotify.Dispose();
            }

    记录2个小技巧
     

  • 相关阅读:
    IDEA下Maven的pom文件导入依赖出现Auto build completed with errors
    org.apache.jasper.JasperException: java.lang.NullPointerException
    Eclipse下导入web项目(Some projects cannot be imported because they already exist in the workspace)
    JS中构造函数的方法定义在原型对象里
    JS变量赋值
    JDBC以及连接池连接MySQL出现时区错误问题
    chrome中如何截取整个网页
    java中final、super、static关键字的使用
    初识less
    根据当前时间显示问候语
  • 原文地址:https://www.cnblogs.com/cxwx/p/1800560.html
Copyright © 2020-2023  润新知