c#MessageBox提示窗弹出后主窗体将不能被操作点击,必须点击
MessageBox中的确定取消按钮后,才能再操作主窗体,那么如何
在MessageBox弹出没有点击弹窗的确定取消按钮,就可对后面的
主窗体操作呢?
采取用异步线程的方法 相当于出来提示窗体后 主窗体的程序在运行,提示窗体的程序也在运行 ;
就避免了因为弹出提示窗体后主线程一直的等待点击取消,整个程序都会耽搁
这个就不要想了,系统自带的MessageBox是模态窗口,也就是showdialog()方式的,除非你自己做messagebox,否则程序就像调试时候的断点一样定在那里
方法一:
asp.net页面如果需要弹出信息框,则需要在前台页面上注册一个javascript脚本,使用alert方法。使用ClientScript.RegisterStartupScript( )方法注册脚本。
ClientScript.RegisterStartupScript( )
RegisterStartupScript(type,key,script)
type:脚本事件的类型,一般用this.GetType()获取
key:脚本事件的名字,不能重复。
script:javascript脚本。
示例:
(1) string script=“alert('注册信息')</scritp>”; ClientScript.RegisterStartupScript(this.GetType(),"success",script);</p> <p>(2)信息框提示后刷新本页面。 string script=“<script>alert('注册信息');location.href=location.href</scritp>”;ClientScript.RegisterStartupScript(this.GetType(),"success",script);</p> <p>(3)信息框提示后转到新页面。 string script=“<script>alert('注册信息');location.href='index.aspx'</scritp>”; ClientScript.RegisterStartupScript(this.GetType(),"success",script);</p> <p>(4)在新窗口中打开新页面。string script=“<script>alert('注册信息');window.open('index.aspx')</scritp>”;ClientScript.RegisterStartupScript(this.GetType(),"success",script);</p> <p>windos.open( )和window.close( )相对应,一个为打开新窗口,一个为关闭当前窗口。</p> <p>总结:模态窗口。该方法为推荐方法。</p> <p>因为经常使用,所以可以将该方法放入一个类中。方法是:新建网站---网站根目录右击---添加ASP.NET文件夹---选择APP_Code----右击APP_Code---添加新项---选择类,到此类文件新建完毕。</p> <p>类中新建方法如下:</p> <p>//弹出信息,信息内容为info</p> <p>public static void Alert(string info, Page p)<br> {<br> string script = "<script>alert('"+info+"')";
p.ClientScript.RegisterStartupScript(p.GetType(),"",script);
}
//调用该类的方法是:
类名.Alert(注册信息,this);因为该方法是静态方法,所以通过类名直接调用。如果该方法不是静态方法,需要实例化对象后在调用。实例化如下:
类名 a=new 类名(); 然后调用: a.Alert(注册成功,this);
可以 open一个新的form,还能自定义美化的提示界面
你可以自己做一个MessageBox
开个新的线程。
参考代码:
private void button6_Click(object sender, EventArgs e)
{
Task task = new Task(showmess);
task.Start();
}
private void showmess()
{
MessageBox.Show("弹窗");
}