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个小技巧
     

  • 相关阅读:
    01-初学总结之《谭浩强C程序设计》
    00-计算机经典参考书籍
    (转)android图片压缩总结
    am等adb命令小总结
    (原创)在service中定时执行网络操作的几点说明
    (转)访问者模式
    (原创)用Receiver和SystemService监听网络状态,注册Receiver的两种方式
    (原创)Activity启动模式之singleTask
    (原创)开发微信公众平台遇到的乱码等问题的解决
    (转载)XML解析之-XStream解析
  • 原文地址:https://www.cnblogs.com/cxwx/p/1800560.html
Copyright © 2011-2022 走看看