| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Windows.Forms;
- //ToastForm _ToastForm = null;
- //public void Toast(string s = "")
- //{
- // if (_ToastForm == null || _ToastForm.IsDisposed)
- // _ToastForm = new ToastForm(this);
- // _ToastForm.Toast(s);
- //}
- namespace Y.Skin.YoForm.Toast
- {
- public partial class ToastForm : Form
- {
- 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;
- }
- }
- }
- }
|