lu
2025-04-14 ecb7a60de1639f520712ce95f99414b0dd2c9713
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Drawing;
using System.Windows.Forms;
 
namespace Gs.DevApp
{
    public partial class Toast : DevExpress.XtraEditors.XtraForm
    {
        private System.Windows.Forms.Timer tmr;
        private System.Windows.Forms.Timer tmr2;
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="it">1成功,-1失败</param>
        /// <param name="messageText"></param>
        /// <param name="vanishingSeconds"></param>
        public Toast(int it, string messageText, int vanishingSeconds = 2)
        {
            InitializeComponent();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Toast));
            if (it > 0)
                this.panel1.BackgroundImage = global::Gs.DevApp.Properties.Resources.ok123;
            else
                this.panel1.BackgroundImage = global::Gs.DevApp.Properties.Resources.error123;
            double elapsedTime = 0;
            testo.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
            {
                tmr.Stop();
                tmr2.Stop();
                tmr.Dispose();
                tmr2.Dispose();
                this.Close();
            };
            tmr.Interval = (int)TimeSpan.FromSeconds(vanishingSeconds).TotalMilliseconds;
            tmr.Start();
 
            //second timer
            tmr2 = new System.Windows.Forms.Timer();
            tmr2.Tick += delegate
            {
                elapsedTime += 50;
 
                if (elapsedTime >= (vanishingMilliSeconds * 65) / 100)
                    this.Opacity -= 0.05f;
 
            };
            tmr2.Interval = (int)TimeSpan.FromMilliseconds(50).TotalMilliseconds;
            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);
        }
    }
}