duheng
2025-03-24 6e1dd6f75cd7265f549a8b9e4d77ff5d88da9651
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
73
74
75
76
77
78
namespace Yw.WinFrmUI
{
    /// <summary>
    /// 提示窗体
    /// </summary>
    public partial class VmoExceptionTipForm : DevExpress.XtraEditors.XtraForm
    {
        /// <summary>
        /// 
        /// </summary>
        public VmoExceptionTipForm()
        {
            InitializeComponent();
            this.labText.ImageOptions.Images = HttpStatusImageHelper.ImgC;
        }
 
        /// <summary>
        /// 设置
        /// </summary>
        public void Set(Yw.Vmo.VException ex, int interval = 3000)
        {
            var imageIndex = 0;
            switch (ex.ErrorStatus)
            {
                case (int)Yw.Dto.eResultCode.Success: imageIndex = 0; break;
                case (int)Yw.Dto.eResultCode.Confirm: imageIndex = 1; break;
                case (int)Yw.Dto.eResultCode.Prompt: imageIndex = 2; break;
                case (int)Yw.Dto.eResultCode.Alert: imageIndex = 3; break;
                case (int)Yw.Dto.eResultCode.Error: imageIndex = 4; break;
                case (int)Yw.Dto.eResultCode.TimeOut: imageIndex = 5; break;
                default: break;
            }
            this.timer1.Enabled = false;
            this.labText.ImageOptions.ImageIndex = imageIndex;
            this.labText.Text = $"[{ex.ErrorCode}]{ex.ErrorMsg}";
            this.timer1.Interval = interval;
            this.timer1.Enabled = true;
            AdaptSize();
        }
 
        //自适应尺寸
        private void AdaptSize()
        {
            int width = 300;
            int height = 80;
            var bestSize = this.labText.CalcBestSize();
            if (width < bestSize.Width + 20)
            {
                width = bestSize.Width + 20;
            }
            if (height < bestSize.Height + 20)
            {
                height = bestSize.Height + 20;
            }
            this.Size = new Size(width, height);
        }
 
        /// <summary>
        /// 绘制边框
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            this.DrawBorder(e, Color.Gray, 1);
        }
 
        //事件
        private void timer_Tick(object sender, EventArgs e)
        {
            this.timer1.Enabled = false;
            this.Close();
        }
 
 
 
    }
}