using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Gs.DevApp
{
public partial class VanishingMessage : DevExpress.XtraEditors.XtraForm
{
private System.Windows.Forms.Timer tmr;
private System.Windows.Forms.Timer tmr2;
///
/// Shows a message windows. 3 sec is the suggested time
///
/// Message
/// Showing time
public VanishingMessage(System.Drawing.Color bgColor,string messageText, int vanishingSeconds = 3)
{
InitializeComponent();
this.Appearance.BackColor = bgColor;
double elapsedTime = 0;
testo.Text = messageText;
double vanishingMilliSeconds = vanishingSeconds * 1000;
// message dimensions
//this.Width = testo.Width + 50;
//this.Height = testo.Height + 50;
//text position
// testo.Location = new Point((this.Width / 2) - (testo.Width / 2), (this.Height / 2) - (testo.Height / 2));
//first timer
tmr = new System.Windows.Forms.Timer();
tmr.Tick += delegate
{
tmr.Stop();
tmr2.Stop();
tmr.Dispose();
tmr2.Dispose();
this.Close();
};
tmr.Interval = (int)TimeSpan.FromSeconds(vanishingSeconds).TotalMilliseconds;
tmr.Start();
//second timer
tmr2 = new System.Windows.Forms.Timer();
tmr2.Tick += delegate
{
elapsedTime += 50;
if (elapsedTime >= (vanishingMilliSeconds * 65) / 100)
this.Opacity -= 0.05f;
};
tmr2.Interval = (int)TimeSpan.FromMilliseconds(50).TotalMilliseconds;
tmr2.Start();
}
private void VanishingMessage_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.DarkRed);
SolidBrush sb = new SolidBrush(Color.DarkRed);
Rectangle r = this.DisplayRectangle;
r.Width -= 1;
r.Height -= 1;
g.DrawRectangle(p, r);
}
}
}