zoukankan      html  css  js  c++  java
  • C# 实现 类似Android的Toast

        public partial class ToastForm : Form
        {
            /// <summary>
            /// 显示毫秒
            /// </summary>
            private int _wait_ms = 1000;
    
    
            public ToastForm(double seconds, string text, Form parent)
                : this(seconds, text, parent, Color.Blue, 15, ContentAlignment.TopCenter)
            {
            }
    
            public ToastForm(double seconds, string text, Form parent, int font_size)
                : this(seconds, text, parent, Color.Blue, font_size, ContentAlignment.TopCenter)
            {
            }
    
    
    
            public ToastForm(double seconds, string text, Form parent, Color text_color, int font_size, ContentAlignment textAlignment)
            {
                InitializeComponent();
                _wait_ms = (int)(seconds * 1000);
                if (font_size != lbShow.Font.Size) lbShow.Font = new Font(lbShow.Font.Name, font_size, lbShow.Font.Style);
                lbShow.Text = text;
                if (lbShow.TextAlign != textAlignment) lbShow.TextAlign = textAlignment;
                this.lbShow.ForeColor = text_color;
                this.Left = parent.Left + (parent.Width - this.Width) / 2;
                this.Top = parent.Top + (parent.Height - this.Height) / 2;
            }
    
            private void ToastForm_Load(object sender, EventArgs e)
            {
                Thread t = new Thread((ThreadStart)delegate
                {
                    Thread.Sleep(_wait_ms);
                    try
                    {
                        this.Invoke(new EventHandler((s1, e1) => this.Close()));
                    }
                    catch
                    {
                    }
                });
                t.IsBackground = true;
                t.Start();
            }
        }
  • 相关阅读:
    cocos2d3.8.1 使用prebuild提升发布android速度
    AS3条件编译
    Box2d FilterData
    旋转关节(Revolute Joint)
    线关节(Line Joint)
    平移关节(Prismatic Joint)
    滑轮关节(b2PulleyJoint)
    PAT Basic 1043 输出PATest (20 分)
    PAT Basic 1042 字符统计 (20 分)
    PAT Basic 1039 到底买不买 (20 分)
  • 原文地址:https://www.cnblogs.com/hbhbice/p/3033252.html
Copyright © 2011-2022 走看看