private void button2_Click(object sender, EventArgs e)
{
System.Windows.Forms.OpenFileDialog openFileDialog1;
openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "选择 Shp 文件";
openFileDialog1.Filter = "Shapefile (*.shp)|*.shp";
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
}
为什么openFileDialog1.ShowDialog方法会影响我之后代码的数据库的读取?使用该方法以后,数据库读取数据为0。我去掉.ShowDialog()之后数据库读取正常。
{
System.Windows.Forms.OpenFileDialog openFileDialog1;
openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "选择 Shp 文件";
openFileDialog1.Filter = "Shapefile (*.shp)|*.shp";
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
}
为什么openFileDialog1.ShowDialog方法会影响我之后代码的数据库的读取?使用该方法以后,数据库读取数据为0。我去掉.ShowDialog()之后数据库读取正常。
比如说textBox1赋值以后引起了什么后果。
不要去怀疑.net本身的问题。
通过showdialog赋值以后,textbox1也有值。
而你别的方法一定是用了执行路径的信息,所以会出错。
总的来说,问题还是出在使用执行路径信息的地方,而不是OpenFileDialog这里。
private void button2_Click(object sender, EventArgs e)
{
System.Windows.Forms.OpenFileDialog openFileDialog1;
openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "选择 Shp 文件";
openFileDialog1.Filter = "Shapefile (*.shp)|*.shp";
if (openFileDialog1.ShowDialog()==DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
}
这是选择文件的button,选择完以后,点击另一个button开始运算private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
textBox1.Enabled = false;
button2.Enabled = false;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
base.SetVisibleCore(false);
Computation computation = new Computation();
computation.FilePath = @textBox1.Text;
computation.Previous = System.DateTime.Now;
Thread.Sleep(60000);
computation.Start();
}实例computation的start方法,首先会从数据库读取数据,然后再调用刚才选择的文件进行计算。
public void Start()
{
while (true)
{
timea = System.Environment.TickCount;
timeTemp = System.DateTime.Now; using (GetGPSPoints getGPSPoint = new GetGPSPoints())
{
list = getGPSPoint.GetPointList(2013,7,15,18,40,20);
} using (NearestCalBatchPoint testpro = new NearestCalBatchPoint())
{
bool testbool = testpro.BatchPointsCal(filePath, ref list, (double)30 / 33 / 3600);
roadSpdIndexLength = testpro.featureClass.FeatureCount(null);
}
第一个using(){}里面就是数据库读取操作 第二using(){}里才会使用被赋值的filepath