| | |
| | | using System; |
| | | using System.Configuration; |
| | | using System.Drawing; |
| | | using System.Windows.Forms; |
| | | |
| | |
| | | /// </summary> |
| | | /// <param name="it">1成功,-1失败</param> |
| | | /// <param name="messageText"></param> |
| | | /// <param name="vanishingSeconds"></param> |
| | | public Toast(int it, string messageText, int vanishingSeconds = 2) |
| | | /// <param name="vanishingSeconds">动画延长时间</param> |
| | | public Toast(int it, string messageText, int vanishingSeconds = 5) |
| | | { |
| | | InitializeComponent(); |
| | | this.StartPosition = FormStartPosition.CenterScreen; // 设置窗体居中显示 |
| | | this.AutoScaleMode = AutoScaleMode.Font; // 根据系统字体大小 |
| | | int clientWidth=0; |
| | | int clientHeight = 0; |
| | | this.lbMsg.BackColor = System.Drawing.Color.Firebrick; |
| | | this.lbMsg.Font = new System.Drawing.Font("Tahoma", 38F); |
| | | this.lbMsg.ForeColor = System.Drawing.Color.White; |
| | | messageText = messageText.Replace("@n", "\r\n"); |
| | | using (Graphics graphics = this.CreateGraphics()) |
| | | { |
| | | Size textSize = TextRenderer.MeasureText(messageText, lbMsg.Font); |
| | | clientWidth = (int)textSize.Width + 10; |
| | | clientHeight= (int)textSize.Height+10; |
| | | } |
| | | this.ClientSize = new System.Drawing.Size(clientWidth, clientHeight); |
| | | this.StartPosition = FormStartPosition.CenterScreen; // 设置窗体居中显示 |
| | | this.AutoScaleMode = AutoScaleMode.Font; // 根据系统字体大小 |
| | | this.CenterToScreen(); |
| | | try |
| | | { |
| | | string _vanishingSeconds = ConfigurationManager.AppSettings["ToastSeconds"]; |
| | | if (!string.IsNullOrEmpty(_vanishingSeconds)) |
| | | vanishingSeconds = int.Parse(_vanishingSeconds); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | } |
| | | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Toast)); |
| | | if (it > 0) |
| | | this.panel1.BackgroundImage = global::Gs.DevApp.Properties.Resources.ok123; |
| | | { |
| | | this.lbMsg.BackColor = System.Drawing.Color.SeaGreen; |
| | | } |
| | | else |
| | | this.panel1.BackgroundImage = global::Gs.DevApp.Properties.Resources.error123; |
| | | { |
| | | this.lbMsg.BackColor = System.Drawing.Color.Firebrick; |
| | | } |
| | | double elapsedTime = 0; |
| | | testo.Text = messageText; |
| | | lbMsg.Text = messageText; |
| | | double vanishingMilliSeconds = vanishingSeconds * 1000; |
| | | // message dimensions |
| | | //this.Width = testo.Width + 50; |
| | | //this.Height = testo.Height + 50; |
| | | //text position |
| | | // testo.Location = new Point((this.Width / 2) - (testo.Width / 2), (this.Height / 2) - (testo.Height / 2)); |
| | | //first timer |
| | | tmr = new System.Windows.Forms.Timer(); |
| | | tmr.Tick += delegate |
| | | { |
| | |
| | | tmr2.Start(); |
| | | } |
| | | |
| | | private void VanishingMessage_Paint(object sender, PaintEventArgs e) |
| | | { |
| | | Graphics g = this.CreateGraphics(); |
| | | Pen p = new Pen(Color.DarkRed); |
| | | SolidBrush sb = new SolidBrush(Color.DarkRed); |
| | | Rectangle r = this.DisplayRectangle; |
| | | r.Width -= 1; |
| | | r.Height -= 1; |
| | | g.DrawRectangle(p, r); |
| | | } |
| | | } |
| | | } |