当前位置:IT168首页 > 技术开发 > 概述
[收藏此页] [打印] [推荐] [评论]

winfrom让弹出的MessageBox在指定时间内自动销毁

责任编辑:nancy作者:ITPUB论坛   2008-07-07   
文本Tag: 微软 sql

【IT168技术文档】

  winfrom让弹出的MessageBox在指定时间内自动销毁,代码如下:
private void Button_Click(object sender, System.EventArgs e) { StartKiller(); MessageBox.Show("这里是MessageBox弹出的内容","MessageBox"); MessageBox.Show("这里是跟随运行的窗口","窗口"); } private void StartKiller() { Timer timer = new Timer(); timer.Interval = 10000;//10秒启动 timer.Tick += new EventHandler(Timer_Tick); timer.Start(); } private void Timer_Tick(object sender, EventArgs e) { KillMessageBox(); //停止计时器 ((Timer)sender).Stop(); } private void KillMessageBox() { //查找MessageBox的弹出窗口,注意对应标题 IntPtr ptr = FindWindow(null,"MessageBox"); if(ptr != IntPtr.Zero) { //查找到窗口则关闭 PostMessage(ptr,WM_CLOSE,IntPtr.Zero,IntPtr.Zero); } } [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;
上一页
1
下一页
收藏到: 添加到“百度搜藏”添加到“QQ书签”添加到“Google书签”添加到“Yahoo收藏”添加到“和讯网摘”
【内容导航】
本文欢迎转载,转载请注明:转载自IT168 [ http://www.it168.com/ ]
本文链接:http://tech.it168.com/d/2008-07-07/200807071659862.shtml
技术开发相关文章  
  • 暂无
友情推介