• C#实现相似QQ的隐藏浮动窗口、消息闪动


    功能简单介绍

      当语音客服系统登录成功进入主界面时,本聊天工具将会自己主动隐藏在左下角位置,当鼠标移动到左下角时,自己主动弹出,当鼠标移开聊天窗口时,自己主动隐藏。假设想让聊天窗口固定在桌面。仅仅要拖动一下聊天窗口,让它不停留在边界位置就能够了。

    隐藏和悬浮方式类型QQ。


    1. 系统主界面

       

    当点击最小化button时, 在电脑右下角会显示任务图标,点击任务图标,将会在左下角位置弹出。

    主界面各部分介绍:

    a) 消息列表:该区域的功能主要是显示消息记录。

    b) 发送消息:输入要发送的消息进行发送,默认群聊。输入消息后,按回车键或者点击“发送”button,将进行消息发送。

    c) 坐席人员:显示全部已登录客服系统的坐席人员,显示方式:名称(状态)

    d) 通知:记录坐席上下线记录

    实现浮动:

            #region 停靠悬浮
            
            internal AnchorStyles StopDock = AnchorStyles.None;
    
            private void StopRectTimer_Tick(object sender, EventArgs e)
            {
                //假设鼠标在窗口上。则依据停靠位置显示整个窗口
                if (this.Bounds.Contains(Cursor.Position))
                {
                    switch (this.StopDock)
                    {
                        case AnchorStyles.Top:
                            this.Location = new Point(this.Location.X, 0);
                            break;
                        case AnchorStyles.Bottom:
                            this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - this.Height);
                            break;
                        case AnchorStyles.Left:
                            this.Location = new Point(0, this.Location.Y);
                            break;
                        case AnchorStyles.Right:
                            this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, this.Location.Y);
                            break;
                    }
                }
                else  //假设鼠标离开窗口,则依据停靠位置隐藏窗口,但须留出部分窗口边缘以便鼠标选中窗口
                {
                    switch (this.StopDock)
                    {
                        case AnchorStyles.Top:
                            this.Location = new Point(this.Location.X, (this.Height - 3) * (-1));
                            break;
                        case AnchorStyles.Bottom:
                            this.Location = new Point(this.Location.X, Screen.PrimaryScreen.Bounds.Height - 5);
                            break;
                        case AnchorStyles.Left:
                            this.Location = new Point((-1) * (this.Width - 3), this.Location.Y);
                            break;
                        case AnchorStyles.Right:
                            this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - 2, this.Location.Y);
                            break;
                    }
                }
            }
    
            private void MainFrm_LocationChanged(object sender, EventArgs e)
            {
                if (this.Top <= 0)
                {
                    this.StopDock = AnchorStyles.Top;
                }
                else if (this.Bottom >= Screen.PrimaryScreen.Bounds.Height)
                {
                    this.StopDock = AnchorStyles.Bottom;
                }
                else if (this.Left <= 0)
                {
                    this.StopDock = AnchorStyles.Left;
                }
                else if (this.Left >= Screen.PrimaryScreen.Bounds.Width - this.Width)
                {
                    this.StopDock = AnchorStyles.Right;
                }
                else
                {
                    this.StopDock = AnchorStyles.None;
                }
            }
    
            #endregion

    有消息来时,不断闪动图标。加入一个定时器,不断切换该图标,监听,消息列表,假设有文字改变。则开启定时器。

            int i = 0; //先设置一个全局变量 i ,用来控制图片索引,然后创建定时事件,双击定时控件就能够编辑 
            private Icon ico1 = new Icon("img/q1.ico"); 
            private Icon ico2 = new Icon("img/q2.ico"); //两个图标 切换显示 以达到消息闪动的效果
    
            //定时器 不断闪动图标
            private void timer1_Tick(object sender, EventArgs e)
            {
                //假设i=0则让任务栏图标变为透明的图标而且退出
                if (i < 1)
                {
                    this.notifyIcon1.Icon = ico2;
                    i++;
                    return;
                }
                //假设i!=0,就让任务栏图标变为ico1,并将i置为0;
                else
                    this.notifyIcon1.Icon = ico1;
                i = 0; 
            }
    
            //有消息来时 闪动
            private void ChatRoomMsg_TextChanged(object sender, EventArgs e)
            {
                this.timer1.Enabled = true;
            }
    
          private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
            {
                if (this.timer1.Enabled)
                {
                    this.timer1.Enabled = false;
                }
                if (e.Button == MouseButtons.Left && this.WindowState == FormWindowState.Minimized)
                {
                    //推断是否已经最小化于托盘 
                    if (WindowState == FormWindowState.Minimized)
                    {
                        this.StopRectTimer.Enabled = false;
    
                        StopDock = AnchorStyles.None;
                        //还原窗口显示 
                        WindowState = FormWindowState.Normal;
                        //激活窗口并给予它焦点 
                        //this.Activate();
                        //任务栏区显示图标 
                        this.ShowInTaskbar = false;
                        //托盘区图标隐藏 
                        //notifyIcon1.Visible = true;
    
                        //默认显示 左下角
                        this.Left = 0;
                        this.Top = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
                    }
                }
            }
    


  • 相关阅读:
    top
    H3C系列之三层交换机系统版本升级
    关于惠普hp服务器开机时F10菜单变成F10 Function Disabled的解决方法
    linux登陆欢迎提示信息的设置
    H3C交换机如何配置管理VLAN
    H3C S3100交换机配置VLAN和远程管理
    设置思科设备console密码、enable密码、vty登录密码
    Windows Server2003本地用户的批量导入和导出(转)
    语音通信质量监测
    Android BaseAdapter加载多个不同的Item布局时出现UncaughtException in Thread main java.lang.ArrayIndexOutOfBoundsException: length=15; index=15
  • 原文地址:https://www.cnblogs.com/lytwajue/p/6734740.html
Copyright © 2020-2023  润新知