zoukankan      html  css  js  c++  java
  • 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个小技巧
     

  • 相关阅读:
    GTK+ 3.6.2 发布,小的 bug 修复版本
    RunJS 新增 Echo Ajax 测试功能
    Mozilla 发布 Popcorn Maker,在线创作视频
    Sina微博OAuth2框架解密
    Mina状态机State Machine
    Mozilla 发布 Shumway —— 纯JS的SWF解析器
    Code Browser 4.5 发布,代码浏览器
    ROSA 2012 "Enterprise Linux Server" 发布
    ltrace 0.7.0 发布,程序调试工具
    Artifactory 2.6.5 发布,Maven 扩展工具
  • 原文地址:https://www.cnblogs.com/cxwx/p/1800560.html
Copyright © 2011-2022 走看看