private void button8_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Excel文件|*.xls";
openFileDialog1.Title = "请选择要导入的文件";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
inFilePath = openFileDialog1.FileName;
label6.Text = "读取中";
readExcel = new System.Threading.Thread(new System.Threading.ThreadStart(getExcelData));
readExcel.Start();
}
}
这段代码单独用的时候没有什么问题 放到我的程序里面 大多数时候没有问题可以执行if语句里面的代码,但是有些时候就不执行,单步调试时发现openFileDialog1.ShowDialog()不反应
{
openFileDialog1.Filter = "Excel文件|*.xls";
openFileDialog1.Title = "请选择要导入的文件";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
inFilePath = openFileDialog1.FileName;
label6.Text = "读取中";
readExcel = new System.Threading.Thread(new System.Threading.ThreadStart(getExcelData));
readExcel.Start();
}
}
这段代码单独用的时候没有什么问题 放到我的程序里面 大多数时候没有问题可以执行if语句里面的代码,但是有些时候就不执行,单步调试时发现openFileDialog1.ShowDialog()不反应
if (openFileDialog1.ShowDialog() == DialogResult.OK)
this.openFileDialog1.InitialDirectory = "C:\\";
this.openFileDialog1.Filter = "excel文件(*.xls)|*.xls";
this.openFileDialog1.FilterIndex = 2;
this.openFileDialog1.RestoreDirectory = true;
this.openFileDialog1.Title = "打开excel文件";
if (openFileDialog1.ShowDialog()==DialogResult.OK)
string sss = openFileDialog1.FileName;这样写一点事也没有,是不是你的其他地方写的不好啊
如果没有了,说明你其他地方对这个对象的操作导致的
this.openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); //设置对话框显示的初始目录
this.openFileDialog1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"; //设置要查找的文件的类型,这里要查找的是图片类型,如jpg、gif等
this.openFileDialog1.FilterIndex = 2;
this.openFileDialog1.Multiselect = true; //设置为可以选择多个图片文件
this.openFileDialog1.RestoreDirectory = true;
DialogResult dr = this.openFileDialog1.ShowDialog();
string fileName = this.openFileDialog1.FileName; //获取对话框中选中的文件的路径和名称
string extendedName = Path.GetExtension(fileName).ToLower(); //得到后缀
string[] allowExtended ={ ".jpg", ".gif", ".png", ".bmp", ".pdf", ".jpeg", ".tif" };
if (extendedName == allowExtended[0] || extendedName == allowExtended[1] || extendedName == allowExtended[2]
|| extendedName == allowExtended[3] || extendedName == allowExtended[4] || extendedName == allowExtended[5]
|| extendedName == allowExtended[6])
{
if (dr == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
//循环选中多个文件进行加载
for (int i = 0; i < openFileDialog1.FileNames.Length; i++)
{
fileName = openFileDialog1.FileNames.GetValue(i).ToString();
using (myStream)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
byte[] imgbyte = new byte[fs.Length];
fs.Read(imgbyte, 0, imgbyte.Length);
fs.Close();
myStream = new MemoryStream(imgbyte);
Bindtest(myStream, fileName);
myStream.Close();
}
}
}
} }
else
{
MessageBox.Show("请上传jpg、gif、png、bmp格式的图片。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
public void Open()
{
OpenFileDialog openFileDialog1=new OpenFileDialog ();
openFileDialog1.Filter = "Excel文件|*.xls";
openFileDialog1.Title = "请选择要导入的文件";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
inFilePath = openFileDialog1.FileName;
label6.Text = "读取中";
readExcel = new System.Threading.Thread(new System.Threading.ThreadStart(getExcelData));
readExcel.Start();}
if (this.openFileDialog1.ShowDialog(this) == DialogResult.OK)
{
}这样试试呢LZ