[DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
public const int WM_CLOSE = 0x10;
/// <summary>
/// 对话框停留时间(毫秒为单位,默认为2000毫秒)
/// </summary>
private int _StopTime = 2000;
/// <summary>
/// 对话框停留时间(毫秒为单位,默认为2000毫秒)
/// </summary>
[Description("对话框停留时间(毫秒为单位,默认为2000毫秒)")]
public int StopTime
{
get { return _StopTime; }
set { _StopTime = value; }
}
private void StartKiller()
{
Timer timer = new Timer();
timer.Interval = StopTime; //3秒啓動
timer.Tick += new EventHandler(Timer_Tick);
timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
KillMessageBox();
((Timer)sender).Stop();
}
private void KillMessageBox()
{
//依MessageBox的標題,找出MessageBox的視窗
IntPtr ptr = FindWindow(null, "提示");
if (ptr != IntPtr.Zero)
{
//找到則關閉MessageBox視窗
PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
}
public void XtraMessBoxShow(string message)
{
StartKiller();
XtraMessageBox.Show(message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
public const int WM_CLOSE = 0x10;
/// <summary>
/// 对话框停留时间(毫秒为单位,默认为2000毫秒)
/// </summary>
private int _StopTime = 2000;
/// <summary>
/// 对话框停留时间(毫秒为单位,默认为2000毫秒)
/// </summary>
[Description("对话框停留时间(毫秒为单位,默认为2000毫秒)")]
public int StopTime
{
get { return _StopTime; }
set { _StopTime = value; }
}
private void StartKiller()
{
Timer timer = new Timer();
timer.Interval = StopTime; //3秒啓動
timer.Tick += new EventHandler(Timer_Tick);
timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
KillMessageBox();
((Timer)sender).Stop();
}
private void KillMessageBox()
{
//依MessageBox的標題,找出MessageBox的視窗
IntPtr ptr = FindWindow(null, "提示");
if (ptr != IntPtr.Zero)
{
//找到則關閉MessageBox視窗
PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
}
public void XtraMessBoxShow(string message)
{
StartKiller();
XtraMessageBox.Show(message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}