| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- //############################################################
- // https://github.com/yuzhengyang
- // author:yuzhengyang
- //############################################################
- using System;
- using System.Windows.Forms;
- namespace Y.Skin.YoForm.Toast
- {
- public partial class ToastForm : Form
- {
- #region How to use?
- //ToastForm _ToastForm = null;
- //public void Toast(string s = "")
- //{
- // if (_ToastForm == null || _ToastForm.IsDisposed)
- // _ToastForm = new ToastForm(this);
- // _ToastForm.Toast(s);
- //}
- #endregion
- Form BaseForm;
- DateTime HideTime = DateTime.Now;
- int Showtime = 5;
- public ToastForm(Form form)
- {
- InitializeComponent();
- BaseForm = form;
- }
- private void ToastForm_Load(object sender, EventArgs e)
- {
- TopMost = true;
- ShowInTaskbar = false;
- }
- private void SetPosition()
- {
- Top = BaseForm.Top + (BaseForm.Height / 2) - (Height / 2);
- Left = BaseForm.Left + (BaseForm.Width / 2) - (Width / 2);
- }
- public void Toast()
- {
- BaseForm.BeginInvoke(new Action(() =>
- {
- Show();
- HideTime = DateTime.Now.AddSeconds(Showtime);
- SetPosition();
- TmActor.Interval = 1000;
- TmActor.Enabled = true;
- }));
- }
- public void Toast(string s)
- {
- BaseForm.BeginInvoke(new Action(() =>
- {
- LbMsg.Text = s;
- Show();
- HideTime = DateTime.Now.AddSeconds(Showtime);
- SetPosition();
- TmActor.Interval = 1000;
- TmActor.Enabled = true;
- }));
- }
- private void TmActor_Tick(object sender, EventArgs e)
- {
- if (DateTime.Now > HideTime)
- {
- Hide();
- TmActor.Enabled = false;
- }
- }
- }
- }
|