我正在用C#编写一个GIS应用程序.应用程序的一部分允许用户选择KML文件,然后程序将处理该文件.我正在使用OpenFileDialog,但问题是所有代码都在对话框关闭之前执行(并且在用户确定文件之后).这需要一段时间,因为该程序必须缩放和做其他事情.有没有办法在我的代码执行之前以编程方式关闭对话框?
编辑:一些代码为那些问.
private void OnKMLFileSet(object sender, CancelEventArgs e)
{
Polygon polygon = KmlToPolygon(openFileDialog2.FileName);
// After this, I no longer need the file, but the dialog stays open until the end of the method
Graphic graphic = new Graphic();
graphic.Geometry = polygon;
textBox1.Text = string.Format("{0:n}", CalculateAreaInSqKilometers(polygon)).Split('.')[0];
textBox2.Text = string.Format("{0:n}", CalculateAreaInSqMiles(polygon)).Split('.')[0];
textBox3.Text = string.Format("{0:n}", CalculateAreaInSqKnots(polygon)).Split('.')[0];
Note polyInfo = new Note("Polygon with nautical area: " + textBox3.Text, polygon);
map.Map.ChildItems.Add(polyInfo);
map.ZoomTo(polygon.GetEnvelope());
}
Run Code Online (Sandbox Code Playgroud)
听起来这个对话框实际上是关闭的,但它仍然是"可见的",因为主窗口很忙并且还没有重新绘制.
一些想法:
编辑:看完代码后,我想我看到了你的问题.您正在处理FileOk事件.这将产生您试图避免的效果.使用如下对话框:
if (openFileDialog1.ShowDialog() == DialogResult.OK) {
// open file
}
Run Code Online (Sandbox Code Playgroud)
不要使用FileOk事件.我以前从来没有理由使用它...也许按照我已经给出的建议可能会有所帮助.
| 归档时间: |
|
| 查看次数: |
1940 次 |
| 最近记录: |