Halcom 发表于 2019-5-11 18:56:10

选择一个文件

OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "JPEG文件|*.jpg*|BMP文件|*.bmp*|TIFF文件|*.tiff*";
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.FilterIndex = 1;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string ImagePath;
                ImagePath = openFileDialog1.FileName;
                HD.action(hWindowControl2.HalconWindow, ImagePath);
            }

Halcom 发表于 2021-12-16 15:47:40

            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "所有文件|*.**";
            openFileDialog1.Filter = "All files (*.*)|*.*";
            if (this.chB_txt.Checked==true)
            {
                openFileDialog1.Filter = "txt files (*.txt)|*.txt";
            }
            else if (this.chB_doc.Checked == true)
            {
                openFileDialog1.Filter = "doc files (*.doc)|*.doc";
            }
            else if (this.chB_docx.Checked == true)
            {
                openFileDialog1.Filter = "docx files (*.docx)|*.docx";
            }
            else if (this.chB_csv.Checked == true)
            {
                openFileDialog1.Filter = "csv files (*.csv)|*.csv";
            }
            else if (this.chB_xls.Checked == true)
            {
                openFileDialog1.Filter = "xls files (*.xls)|*.xls";
            }
            else if (this.chB_xlsx.Checked == true)
            {
                openFileDialog1.Filter = "xlsx files (*.xlsx)|*.xlsx";
            }
            else if (this.chB_xml.Checked == true)
            {
                openFileDialog1.Filter = "xml files (*.xml)|*.xml";
            }
            openFileDialog1.FilterIndex = 1;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string filename = openFileDialog1.FileName;
                this.tB_FilePath.Text = filename.ToString();
                this.button1.Enabled = true;
                this.button2.Enabled = true;
            }
页: [1]
查看完整版本: 选择一个文件