WebSocketSharp 請參考官網
https://github.com/sta/websoc...
坑:git
ws.OnMessage += (sender, e) => { BalloonForm balloon = new
BalloonForm("標題", "內容", "底部");githubballoon.Visible = false; balloon.ShowDialog();//此處彈窗必須使用模式對話框,不然窗體打開裏面控件樣式不顯示,鼠標一直顯示加載狀態}web
彈窗代碼安全
using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace xxxx.page { public class BalloonForm : Form { private System.ComponentModel.IContainer components = null; private Label title; private Label textContent; private Label staticTime; private Timer timer1; private Timer timer2; private Timer timer3; public int StayTime = 5000; private int heightMax, widthMax; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.title = new Label(); this.textContent = new Label(); this.staticTime = new Label(); this.timer1 = new Timer(this.components); this.timer2 = new Timer(this.components); this.timer3 = new Timer(this.components); this.SuspendLayout(); // // title // this.title.AutoSize = true; this.title.Location = new Point(10, 10); this.title.Name = "title"; this.title.TabIndex = 0; this.title.Text = "標題"; // // textContent // this.textContent.AutoSize = true; this.textContent.Location = new Point(30, 40); this.textContent.Font= new Font("宋體",12, FontStyle.Bold, GraphicsUnit.Point, ((byte)(134))); this.textContent.Name = "textContent"; this.textContent.TabIndex = 0; this.textContent.Text = "內容"; // // staticTime // this.staticTime.AutoSize = true; this.staticTime.Location = new Point(120, 90); this.staticTime.Name = "staticTime"; this.staticTime.TabIndex = 0; this.staticTime.Text = "開始時間"; // // timer1 // this.timer1.Interval = 10; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // timer2 // this.timer2.Interval = 10; this.timer2.Tick += new System.EventHandler(this.timer2_Tick); // // timer3 // this.timer3.Interval = 10; this.timer3.Tick += new System.EventHandler(this.timer3_Tick); // // BalloonForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.White; this.ClientSize = new System.Drawing.Size(200, 120); this.Controls.Add(this.title); this.Controls.Add(this.textContent); this.Controls.Add(this.staticTime); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "BalloonForm"; this.Opacity = 1; this.ShowIcon = false; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "BalloonForm"; this.TopMost = true; this.Load += new System.EventHandler(this.BalloonForm_Load); //this.ResumeLayout(false); //this.PerformLayout(); } #endregion public string BalloonText { get { return this.title.Text; } set { this.title.Text = value; } } public Color BalloonBackColor { get { return this.BackColor; } set { this.BackColor = value; } } public Color BalloonForeColor { get { return this.title.ForeColor; } set { this.title.ForeColor = value; } } public BalloonForm(string title,string textContent,string staticTime) { //方法一:不進行跨線程安全檢查 CheckForIllegalCrossThreadCalls = false; InitializeComponent(); this.title.Text = title; this.textContent.Text = textContent; this.staticTime.Text = staticTime; this.HeightMax = 120;//窗體滾動的高度 this.WidthMax = 260;//窗體滾動的寬度 this.ScrollShow(); } private void timer1_Tick(object sender, EventArgs e) { ScrollUp(); } private void timer2_Tick(object sender, EventArgs e) { timer2.Enabled = false; timer3.Enabled = true; } private void timer3_Tick(object sender, EventArgs e) { ScrollDown(); } public int HeightMax { set { heightMax = value; } get { return heightMax; } } public int WidthMax { set { widthMax = value; } get { return widthMax; } } public void ScrollShow() { this.Width = widthMax; this.Height = 0; this.Show(); this.timer1.Enabled = true; } private void ScrollUp() { if (Height < heightMax) { this.Height += 3; this.Location = new Point(this.Location.X, this.Location.Y - 3); } else { this.timer1.Enabled = false; this.timer2.Enabled = true; } } private void ScrollDown() { if (Height > 3) { this.Height -= 3; this.Location = new Point(this.Location.X, this.Location.Y + 3); } else { this.timer3.Enabled = false; this.Close(); } } private void BalloonForm_Load(object sender, EventArgs e) { Screen screen = Screen.PrimaryScreen; ;//獲取屏幕變量 this.Location = new Point(screen.WorkingArea.Width - widthMax - 20, screen.WorkingArea.Height - 38);//WorkingArea爲Windows桌面的工做區 this.timer2.Interval = StayTime; } } }