我正在用 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());
}