QQ 有某些新闻,就会在右下角弹出一个提示框,请问这个用 WINFORM(C#) 怎么做啊?
当然, 我说的不是 它的那个效果。
是怎样判断服务器有新消息了,
服务器又怎样把消息发送到客户端,
客户端又怎样接收,
接收后怎样触发事件弹出这个框来。希望各位前辈 给个详细的方案我,或者 有源码 研究一下的。感激不尽!

解决方案 »

  1.   


    用个timer做个定时请求新消息有就弹出。。
      

  2.   

    楼上的哥哥 麻烦详细点可好,我是超级菜鸟啊。。还有,是在UI线程里面做 还是 另外的线程里面啊你能不能给我写个 DEMO啊。 。感激不尽!
      

  3.   

    自己看,WinForm下的消息通知
      

  4.   

    http://www.codeproject.com/ 这个网站上我以前看见过一个消息提示的代码 你可以搜索下..
      

  5.   


    VS2005 设计器代码,需要修正一下,我里面用了图片partial class PromptFrm
        {
            /// <summary>
            /// 必需的设计器变量。
            /// </summary>
            private System.ComponentModel.IContainer components = null;        /// <summary>
            /// 清理所有正在使用的资源。
            /// </summary>
            /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        #region Windows 窗体设计器生成的代码        /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.m_timerShow = new System.Windows.Forms.Timer(this.components);
                this.m_LnkMain = new System.Windows.Forms.LinkLabel();
                this.m_Main = new System.Windows.Forms.Label();
                this.m_picLock = new System.Windows.Forms.PictureBox();
                this.m_picExit = new System.Windows.Forms.PictureBox();
                this.m_toolTip = new System.Windows.Forms.ToolTip(this.components);
                ((System.ComponentModel.ISupportInitialize)(this.m_picLock)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.m_picExit)).BeginInit();
                this.SuspendLayout();
                // 
                // m_timerShow
                // 
                this.m_timerShow.Interval = 10;
                // 
                // m_LnkMain
                // 
                this.m_LnkMain.AutoSize = true;
                this.m_LnkMain.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
                this.m_LnkMain.Location = new System.Drawing.Point(39, 47);
                this.m_LnkMain.Name = "m_LnkMain";
                this.m_LnkMain.Size = new System.Drawing.Size(140, 19);
                this.m_LnkMain.TabIndex = 3;
                this.m_LnkMain.TabStop = true;
                this.m_LnkMain.Text = "在这里显示内容提示内容";
                this.m_LnkMain.UseCompatibleTextRendering = true;
                // 
                // m_Main
                // 
                this.m_Main.AutoSize = true;
                this.m_Main.Location = new System.Drawing.Point(37, 6);
                this.m_Main.Name = "m_Main";
                this.m_Main.Size = new System.Drawing.Size(29, 12);
                this.m_Main.TabIndex = 5;
                this.m_Main.Text = "标题";
                // 
                // m_picLock
                // 
                this.m_picLock.Image = global::Billionlink.UI.WinForm.BaseFrm.Properties.Resources.UnLock;
                this.m_picLock.Location = new System.Drawing.Point(3, 2);
                this.m_picLock.Name = "m_picLock";
                this.m_picLock.Size = new System.Drawing.Size(32, 32);
                this.m_picLock.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                this.m_picLock.TabIndex = 6;
                this.m_picLock.TabStop = false;
                this.m_toolTip.SetToolTip(this.m_picLock, "Lock Tips");
                // 
                // m_picExit
                // 
                this.m_picExit.Image = global::Billionlink.UI.WinForm.BaseFrm.Properties.Resources.TipsExit;
                this.m_picExit.Location = new System.Drawing.Point(259, 2);
                this.m_picExit.Name = "m_picExit";
                this.m_picExit.Size = new System.Drawing.Size(16, 16);
                this.m_picExit.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                this.m_picExit.TabIndex = 4;
                this.m_picExit.TabStop = false;
                this.m_toolTip.SetToolTip(this.m_picExit, "Close Tips");
                // 
                // PromptFrm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.BackColor = System.Drawing.Color.Cornsilk;
                this.ClientSize = new System.Drawing.Size(278, 209);
                this.Controls.Add(this.m_picLock);
                this.Controls.Add(this.m_Main);
                this.Controls.Add(this.m_picExit);
                this.Controls.Add(this.m_LnkMain);
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                this.Name = "PromptFrm";
                this.ShowInTaskbar = false;
                this.Text = "PromptFrm";
                this.TopMost = true;
                this.Load += new System.EventHandler(this.PromptFrm_Load);
                ((System.ComponentModel.ISupportInitialize)(this.m_picLock)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.m_picExit)).EndInit();
                this.ResumeLayout(false);
                this.PerformLayout();        }        #endregion        private System.Windows.Forms.Timer m_timerShow;
            private System.Windows.Forms.LinkLabel m_LnkMain;
            private System.Windows.Forms.PictureBox m_picExit;
            private System.Windows.Forms.Label m_Main;
            private System.Windows.Forms.PictureBox m_picLock;
            private System.Windows.Forms.ToolTip m_toolTip;
        }
      

  6.   

    VS2005 CS代码using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace Billionlink.UI.WinForm.BaseFrm
    {
        /// <summary>
        /// 提醒功能窗口
        /// </summary>
        public partial class PromptFrm : ImeFrm
        {
            #region -变量定义        /// <summary>
            /// 保存鼠标按下时鼠标在窗口的坐标
            /// </summary>
            private int m_CurX = 0;        /// <summary>
            /// 保存鼠标按下时鼠标在窗口的坐标
            /// </summary>
            private int m_CurY = 0;        /// <summary>
            /// 鼠标按下为true
            /// </summary>
            private bool m_MouseDown = false;        /// <summary>
            /// 取得或者设置用户是否可以移动提示框
            /// </summary>
            private bool m_bCanMove = true;        /// <summary>
            /// 单击提示信息事件(非设计器事件)
            /// </summary>
            public event DelegateClickPrompt ClickPromptEventHandler;        /// <summary>
            /// 点击“退出”按钮事件
            /// </summary>
            public event EventHandler<CusEventArgs> ExitEventHandler;        /// <summary>
            /// 提示窗口停留的延迟时间
            /// </summary>
            private int m_lStayTime    = 1000 * 6;        /// <summary>
            /// 计数窗口停留的延迟时间
            /// </summary>
            private int m_lStayTimeTick = 0;        /// <summary>
            /// 窗口弹出时的步进值(默认每个间隔1个象素)
            /// </summary>
            private int m_nSetp        = 2;        /// <summary>
            /// 窗口的真实高度
            /// </summary>
            private int m_nRealHeight = 160;        /// <summary>
            /// 表示是否由用户关闭了窗口
            /// </summary>
            private bool m_bUserClose = false;        /// <summary>
            /// 是否锁定Tips显示状态
            /// </summary>
            private bool m_bIsLock = false;        /// <summary>
            /// 取得提示窗口是否显示
            /// </summary>
            private bool m_bIsVisible = false;        /// <summary>
            /// 开始渐现窗口
            /// </summary>
            private bool m_bStart = true;        #endregion        #region -构造函数        /// <summary>
            /// 构造函数
            /// </summary>
            public PromptFrm()
            {
                InitializeComponent();
                this.m_nRealHeight = this.Height;
                this.Visible = false;
            }                #endregion        #region -属性        /// <summary>
            /// 提示窗口停留的延迟时间(以毫秒为单位,赋值-1则永远停留)
            /// </summary>
            public int PromptDelayTime
            {
                get
                {
                    return this.m_lStayTime;
                }
                set
                {
                    if (value <= -1)
                    {
                        this.m_lStayTime = Int32.MaxValue;
                    }
                    else
                    {
                        this.m_lStayTime = value;
                    }
                }
            }        /// <summary>
            /// 取得或设置提示窗口的标题
            /// </summary>
            public string PromptTitle
            {
                get
                {
                    return this.m_Main.Text;
                }
                set
                {
                    this.m_Main.Text = value;
                }
            }        /// <summary>
            /// 取得或设置提示窗口的内容
            /// </summary>
            public string PromptText
            {
                get
                {
                    return this.m_LnkMain.Text;
                }
                set
                {
                    this.m_LnkMain.Text = value;
                }
            }        /// <summary>
            /// 窗口弹出时的步进值(默认每个间隔1个象素)
            /// </summary>
            public int Setp
            {
                get
                {
                    return this.m_nSetp;
                }
                set
                {
                    this.m_nSetp = value;
                }
            }        /// <summary>
            /// 取得或者设置用户是否可以移动提示框
            /// </summary>
            public bool CanMove
            {
                get
                {
                    return this.m_bCanMove;
                }
                set
                {
                    this.m_bCanMove = value;
                }
            }        /// <summary>
            /// 取得提示窗口是否显示
            /// </summary>
            public bool IsVisible
            {
                get
                {
                    return this.m_bIsVisible;
                }           
            }        #endregion        #region -窗口事件        /// <summary>
            /// Load...
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void PromptFrm_Load(object sender, EventArgs e)
            {
                this.m_picLock.Click      += new EventHandler(m_picLock_Click);
                this.m_picExit.Click      += new EventHandler(m_picExit_Click);
                this.m_picExit.MouseEnter += new EventHandler(m_picExit_MouseEnter);
                this.m_picExit.MouseLeave += new EventHandler(m_picExit_MouseLeave);
                this.Paint                += new PaintEventHandler(PromptFrm_Paint);
                this.m_timerShow.Tick     += new EventHandler(m_timerShow_Tick);                       
                this.m_LnkMain.Click      += new EventHandler(m_LnkMain_Click);            //上升窗口代码
                //this.Height = 0;
                //this.Location = new Point(Screen.AllScreens[0].WorkingArea.Width - this.Width - 3, Screen.AllScreens[0].WorkingArea.Height - 3);
                // 改为渐变显示
                this.Location = new Point(Screen.AllScreens[0].WorkingArea.Width - this.Width - 5, Screen.AllScreens[0].WorkingArea.Height - this.Height - 30);
            }        /// <summary>
            /// 锁定窗口
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void m_picLock_Click(object sender, EventArgs e)
            {
                if (this.m_timerShow.Enabled)
                {
                    this.m_bIsLock = !this.m_bIsLock;
                    this.m_picLock.Image = this.m_bIsLock ? global::Billionlink.UI.WinForm.BaseFrm.Properties.Resources.Lock : global::Billionlink.UI.WinForm.BaseFrm.Properties.Resources.UnLock;
                }
            }        /// <summary>
            /// 绘制边框
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void PromptFrm_Paint(object sender, PaintEventArgs e)
            {
                ControlPaint.DrawBorder(e.Graphics, new Rectangle(0, 0, this.Width, this.Height), Color.Black, ButtonBorderStyle.Solid);
            }        
      

  7.   


    接着上面的,这三个回复是提醒窗口的代码,支持上升、和渐隐、渐现模式/// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void m_picExit_MouseLeave(object sender, EventArgs e)
            {
                //this.m_picExit.Location = new Point(this.m_picExit.Location.X + 1, this.m_picExit.Location.Y);
                this.m_picExit.Height -= 1;
                this.m_picExit.Width  -= 1;
            }        /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void m_picExit_MouseEnter(object sender, EventArgs e)
            {
                //this.m_picExit.Location = new Point(this.m_picExit.Location.X - 1, this.m_picExit.Location.Y);
                this.m_picExit.Height += 1;
                this.m_picExit.Width  += 1;
            }        #endregion        #region -窗体移动        /// <summary>
            /// 鼠标按下
            /// </summary>
            /// <param name="e"></param>
            protected override void OnMouseDown(MouseEventArgs e)
            {
                base.OnMouseDown(e);
                if (this.m_bCanMove)
                {
                    this.m_CurX = e.X;                           //保存鼠标按下是鼠标在窗口的坐标
                    this.m_CurY = e.Y;
                    this.m_MouseDown = true;
                }
            }
            /// <summary>
            /// 鼠标抬起
            /// </summary>
            /// <param name="e"></param>
            protected override void OnMouseUp(MouseEventArgs e)
            {
                base.OnMouseUp(e);
                if (this.m_bCanMove)
                {
                    this.m_MouseDown = false;
                }
            }
            /// <summary>
            /// 鼠标移动
            /// </summary>
            /// <param name="e"></param>
            protected override void OnMouseMove(MouseEventArgs e)
            {
                base.OnMouseMove(e);
                if (this.m_bCanMove && this.m_MouseDown)
                {
                    //Cursor.Position .X Cursor.Position .Y 是屏幕坐标
                    //用屏幕坐标减窗口坐标以保持鼠标总是在窗口的原位置.
                    this.SetDesktopLocation(Cursor.Position.X - this.m_CurX, Cursor.Position.Y - this.m_CurY);
                }
            }        #endregion               #region -计时器事件        /// <summary>
            /// 显示提示窗口(采用缓慢提升窗口方式显示)
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void m_timerShow_Tick(object sender, EventArgs e)
            {
                //上升窗口代码
                // 显示窗口,直到正常高度
                //if (this.Height <= this.m_nRealHeight)
                //{
                //    // 增加高度,降低Y坐标
                //    this.Height += this.m_nSetp;
                //    this.Location = new Point(this.Location.X, this.Location.Y - this.m_nSetp);
                //    this.Refresh();
                //}
                if (this.Opacity < 1.0F && this.m_bStart)
                {                
                    this.Opacity += 0.01F;
                    if (this.Bounds.Contains(Cursor.Position))
                    {
                        this.Opacity = 1.0F;
                    }
                    if (this.Opacity >= 1.0F)
                    {
                        this.m_bStart = false;
                    }
                }
                else
                {
                    // 计数完成后,开始隐藏窗口
                    if (this.m_lStayTimeTick >= this.m_lStayTime)
                    {
                        // 隐藏过程中,如果用户操作提示框,则提示框变为不透明,且重新计数隐藏延迟时间
                        if ((!this.m_bUserClose && this.Bounds.Contains(Cursor.Position)) || this.m_bIsLock)
                        {
                            this.m_lStayTimeTick = 0;
                            this.Opacity = 1.0F;
                            return;
                        }
                        if (this.Opacity > 0F)
                        {
                            this.Opacity -= 0.01F;
                        }
                        else
                        {
                            // 所有变量初始化
                            //上升窗口代码
                            //this.Location = new Point(Screen.AllScreens[0].WorkingArea.Width - this.Width - 3, Screen.AllScreens[0].WorkingArea.Height - 3);
                            //this.Height = 0;
                            // 改为渐变显示
                            this.Location = new Point(Screen.AllScreens[0].WorkingArea.Width - this.Width - 5, Screen.AllScreens[0].WorkingArea.Height - this.Height - 30);                        this.m_bUserClose = false;
                            this.m_lStayTimeTick = 0;
                            this.m_timerShow.Enabled = false;
                            this.m_picLock.Image = global::Billionlink.UI.WinForm.BaseFrm.Properties.Resources.UnLock;
                            this.m_bIsLock = false;
                            this.m_bIsVisible = false;
                            this.m_bStart = true;
                        }
                    }
                    else
                    {
                        // 如果此时用户选择退出,则终止计数
                        if (this.m_bUserClose)
                        {
                            this.m_lStayTimeTick = this.m_lStayTime;
                            this.m_bIsLock = false;
                            return;
                        }
                        // 提示框弹出后,开始计数
                        this.m_lStayTimeTick += this.m_timerShow.Interval;
                    }
                }
            }        #endregion        #region -控件事件        /// <summary>
            /// 关闭提示窗口
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void m_picExit_Click(object sender, EventArgs e)
            {
                if (this.ExitEventHandler != null)
                {
                    CusEventArgs Args = new CusEventArgs("Exit");
                    this.ExitEventHandler(this, Args);
                    if (Args.Cancel)
                    {
                        return;
                    }
                }
                if (this.m_timerShow.Enabled)
                {
                    // 关闭延迟计时,并开始隐藏窗口
                    this.m_bUserClose = true;
                }
                else
                {
                    this.Visible = false;
                    this.m_bIsVisible = false;
                }            
            }        /// <summary>
            /// 单击提示内容
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void m_LnkMain_Click(object sender, EventArgs e)
            {
                if (this.ClickPromptEventHandler != null)
                {
                    this.ClickPromptEventHandler(new PromptEventArgs(""));
                }
                else
                {
                }
            }        #endregion        #region -接口
            
            /// <summary>
            /// 显示提示窗口
            /// </summary>
            /// <param name="strText">显示的文本</param>
            /// <param name="strTitle">标题</param>
            /// <param name="bIsAnimation">是否采用动画</param>
            public void ShowPromptFrm(string strText, string strTitle, bool bIsAnimation)
            {
                if (this.m_bIsVisible)
                {
                    return;
                }
                if (bIsAnimation)
                {
                    this.m_Main.Text = strTitle;
                    this.m_LnkMain.Text = strText;
                    //上升窗口代码
                    //this.Opacity = 1.0F;
                    this.Opacity = 0.0F;
                    this.m_bStart = true;                this.Show();
                    //WAToolsWin32.Win32API.ShowWindow(this.Handle, (short)WAToolsWin32.ShowWindowStyles.SW_SHOWNOACTIVATE);            
                    this.m_timerShow.Enabled = true;
                    this.m_bIsVisible = true;
                }
                else
                {
                    this.m_timerShow.Enabled = false;
                    this.m_Main.Text = strTitle;
                    this.m_LnkMain.Text = strText;
                    this.Opacity = 1.0F;
                    this.Height = this.m_nRealHeight;
                    //switch (tsp)
                    //{
                    //    case TipsShowPoint.RightBottom:
                    //        this.Location = new Point(CommonBase.MainMdiForm.ClientRectangle.Width - this.Width - 3, CommonBase.MainMdiForm.ClientRectangle.Height - this.Height - 3);
                    //        break;                //    case TipsShowPoint.LeftTop:
                    //        this.Location = new Point(CommonBase.MainMdiForm.ClientRectangle.Right - this.Width - 3, CommonBase.MainMdiForm.ClientRectangle.Top + 3);
                    //        break;
                    //}                this.Show();
                    this.m_bIsVisible = true;
                }
            }                      #endregion
        }
    }
      

  8.   

    如果不采用WCF或Remoteing或Socket,客户端是无法从服务器读取新闻的。
    当然你可以采用以上的方式,这样客户端和服务器端就可以实时连接,读取新闻。
    这样做会增大服务器压力,编码难度稍大通常的做法是在服务器上开一个webservice或者写一个aspx页面,
    然后客户端定时读取webservice或aspx页面我采用的是webservice方式,客户端用异步委托(你可以用Timer,这个简单)每60秒访问一次服务器,读取最新的新闻,新闻是否是最新的可以通过时间字段进行判断。
    当有新的新闻的时候,弹出提示框。这里有个问题,你要注意。提示框是通过Show()弹出,当提示框正在弹出或已经弹出的时候,如果一个ShowDialog()的模态窗口也弹出,则提示框将被模态窗口阻止,直到你关闭模态窗口为止
    所谓阻止就是不能操作,看还是可以的
      

  9.   

    任务栏提示器(TaskBar Notifier)
    自己看吧 就这个
      

  10.   

    isjoe大哥,你给的代码 是 怎样 做出那个弹窗的效果的吧?其实我是想看  你下面 说的那些 的 代码实现  用Timer 访问 webservice 怎样实现的。。
      

  11.   

    我想问的是:你是要Winform还是Webform?
      

  12.   

    用timer定时器和Socket网络编程
      

  13.   

    C#写么?
    可以用windows service实现
      

  14.   

    建议去51aspx论坛看看 有现成的