| | |
| | | public Toast(int it, string messageText, int vanishingSeconds = 5) |
| | | { |
| | | InitializeComponent(); |
| | | messageText=messageText.Replace("@n", "\r\n"); |
| | | 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"]; |
| | |
| | | tmr2.Interval = (int)TimeSpan.FromMilliseconds(50).TotalMilliseconds; |
| | | tmr2.Start(); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |