Form.ShowDialog(this)
有时遇到一种情况,.ShowDialog()不显示。也不报错。例如以下:
<span style="font-size:14px;"> private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(show);
thread.Start();
}
void show()
{
Control.CheckForIllegalCrossThreadCalls = false;
//this.Invoke(new Action(() =>
//{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{ }
//}));
}</span>
原因分析:这属于线程间操作的一种异常。界面呈现和新创建的thread分开在两个线程中。在thread线程中
不可以进行界面呈现,即显示.ShowDialog();
解决方法:1:加入參数this。
.ShowDialog(IWin32Window owner); //owner:表示将拥有模式对话框的顶级窗体
<span style="font-size:14px;"> private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(show);
thread.Start();
}
void show()
{
Control.CheckForIllegalCrossThreadCalls = false;
//this.Invoke(new Action(() =>
//{
if (saveFileDialog1.ShowDialog(this) == DialogResult.OK)
{ }
//}));
}</span>
2:使用Invoke
private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(show);
thread.Start();
}
void show()
{
// Control.CheckForIllegalCrossThreadCalls = false;
this.Invoke(new Action(() =>
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{ }
}));
}
Form.ShowDialog(this)的更多相关文章
- 知道Form.Show()和Form.ShowDialog()的区别吗
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:知道Form.Show()和Form.ShowDialog()的区别吗.
- form.Show()和form.ShowDialog()的区别、新建一个form和MessageBox.Show()的常见用法
一:form.Show()和form.ShowDialog()的区别 a. 任何窗体(派生于基类Form的类),都可以以两种方式进行显示. //非模式窗体From qform=new Form();q ...
- Form.ShowDialog和Form.DialogResult
The dialog result of a form is the value that is returned from the form when it is displayed as a mo ...
- Application.Run()和Form.Show()以及Form.ShowDialog()
ShowDialog()弹出模式化的窗体 Show()弹出非模式化的窗体 模式窗体,在关闭或隐藏前无法切换到主窗体. 非模式窗体,变换焦点使不必关闭窗体 总结:显示重要的信息,还是用模式窗体,如删除文 ...
- Waiting Processed Cancelable ShowDialog
namespace ConsoleApplication { using System; using System.Threading; using Microshaoft; /// <summ ...
- C# 窗体位置 Show和ShowDialog(转)
CenterParent 窗体在其父窗体中居中. CenterScreen 窗体在当前显示窗口中居中,其尺寸在窗体大小中指定. Manual 窗体的位置由 Location 属性确定. Windows ...
- C# 非模式窗体show()和模式窗体showdialog()的区别(转)
对话框不是模式就是无模式的.模式对话框,在可以继续操作应用程序的其他部分之前,必须被关闭(隐藏或卸载).例如,如果一个对话框,在可以切换到其它窗 体或对话框之前要求先单击“确定”或“取消”,则它就是模 ...
- C#学习笔记——Show()与ShowDialog()的区别
用Show()调用的窗体不会返回任何值,在使用form.Show()显示form以后,会马上继续执行form.Show()后面的语句.而用ShowDialog()调用的窗体会返回一个DialogRes ...
- show()与showDialog()的区别
A.WinForm中窗体显示 显示窗体可以有以下2种方法: Form.ShowDialog方法 (窗体显示为模式窗体) Form.Show方法 (窗体显示为无模式窗体) 2者具体区别如下: 1.在 ...
随机推荐
- Reverse Engineering the NC ECU (revisited) -- SH7508
http://forum.miata.net/vb/showthread.php?t=536601 Hey all! About 5 years ago, there was a great thre ...
- 追踪CPU跑满
http://blog.donghao.org/2014/04/24/%e8%bf%bd%e8%b8%aacpu%e8%b7%91%e6%bb%a1/
- 自定义圆形控件RoundImageView并认识一下attr
昨天我们学习了自定义带图片和文字的ImageTextButton,非常简单,我承诺给大家要讲一下用自定义属性的方式学习真正的实现自定义控件,在布局文件中使用属性的方式就需要用到attr.xml这个文件 ...
- andriod 浏览文件
protected void browse() { Intent it = new Intent(Intent.ACTION_GET_CONTENT); //创建动作为 "选取" ...
- extjs表单验证
extjs表单验证 //放在onReady的function(){}中 Ext.QuickTips.init(); //为组件提供提示信息功能,form的主要提示信息就是客户端验证的错误信息. Ext ...
- 将React Native集成至Android原生应用
将React Native集成至Android原生应用 Android Studio 2.1 Preview 4生成的空项目 react-native 环境 0.22.2 初次编译后apk有1.1M, ...
- html在线编辑器汇总
1. TinyMCE 免费,开源,轻量的在线编辑器,基于 JavaScript,高度可定制,跨平台. 2. FCKEditor 免费,开源,用户量庞大的在线编辑器,有良好的社区支持. 3. YUI E ...
- poj 1007 Quoit Design(分治)
Quoit Design Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 混沌数学之Henon模型
相关DEMO参见:混沌数学之离散点集图形DEMO 相关代码: // http://wenku.baidu.com/view/d51372a60029bd64783e2cc0.html?re=view ...
- html 制作复杂table
数据分析,一般都需要显示数据,就需要使用html做复杂的表格.复杂表格一般是对td的rowspan .colspan属性值. 在html中<td> 标签定义 HTML 表格中的标准单元格. ...