lu
2025-11-08 ab6b5aaa9c12693003410e1b836d466340793c21
DevApp/Gs.DevApp/UserControl/Toast.cs
@@ -10,7 +10,6 @@
        private System.Windows.Forms.Timer tmr;
        private System.Windows.Forms.Timer tmr2;
        /// <summary>
        /// 
        /// </summary>
@@ -20,9 +19,24 @@
        public Toast(int it, string messageText, int vanishingSeconds = 5)
        {
            InitializeComponent();
            this.testo.Appearance.BackColor = System.Drawing.Color.Firebrick;
            this.testo.Appearance.Font = new System.Drawing.Font("Tahoma", 38F);
            this.testo.Appearance.ForeColor = System.Drawing.Color.White;
            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;
                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"];
@@ -36,14 +50,14 @@
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Toast));
            if (it > 0)
            {
                this.testo.Appearance.BackColor = System.Drawing.Color.SeaGreen;
                this.lbMsg.BackColor = System.Drawing.Color.SeaGreen;
            }
            else
            {
                this.testo.Appearance.BackColor = System.Drawing.Color.Firebrick;
                this.lbMsg.BackColor = System.Drawing.Color.Firebrick;
            }
            double elapsedTime = 0;
            testo.Text = messageText;
            lbMsg.Text = messageText;
            double vanishingMilliSeconds = vanishingSeconds * 1000;
            tmr = new System.Windows.Forms.Timer();
            tmr.Tick += delegate
@@ -71,15 +85,5 @@
            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);
        }
    }
}