ddc
联网
平面设计 画册 VI欣赏 包装 CG-插画 搜索 个人网页 Alexa排名 CSS 建站资源 下载专区 JS特效 品牌服装 服装院校 专题欣赏 SEO 图标欣赏 专题
网站建设 域名注册 网站建设 虚拟主机 广州网站设计 域名注册 广州网站建设 上海网站建设 虚拟主机 广州网页设计 虚拟主机 域名注册 acg王国 ACG玩家 品牌设计 上海网站建设
求创科技
网站建设
中国互联
素材出售
中国设计秀
中资源
当前位置:网络学院首页 >> 编程开发 >> .net >> 在规定时间内自动关闭MessageBox弹出窗口的实现代码

在规定时间内自动关闭MessageBox弹出窗口的实现代码 (2)

来源:中国设计秀    作者:    点击:356     加入收藏    发表评论
0
顶一下

            // button1
            //
            this.button1.Location = new System.Drawing.Point(176, 48);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(96, 24);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }
        #endregion

        /**//// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        ...{
            Application.Run(new Form1());
        }

        private void button1_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;
    }
}
只要新建一个Winform项目并添加以下文件代码即可测试...

[1] [2]
2007-08-27 16:07:00    出处:
Google
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明 | 网站公告 | 友情链接 | 留言 | 旧版入口