小编Sta*_*ler的帖子

如何在 OpenFileDialog 对话框中编写取消按钮的代码

每当我取消 OpenFileDialog 框时。它给出错误路径为空。我的打开文件对话框

有什么方法可以为 OpenFileDialog 的取消按钮和关闭按钮编写代码

我的代码:

       private void button4_Click(object sender, EventArgs e)
        {
            string s = image_print() + Print_image();
            PrintFactory.sendTextToLPT1(s); / sending to serial port
        }

        private string image_print()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            string path = "";
            string full_path = "";
            string filename_noext = "";
            ofd.InitialDirectory = @"C:\ZTOOLS\FONTS";
            ofd.Filter = "GRF files (*.grf)|*.grf";
            ofd.FilterIndex = 2;
            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                filename_noext = System.IO.Path.GetFileName(ofd.FileName);
                path = Path.GetFullPath(ofd.FileName);
                img_path.Text = filename_noext;
                //MessageBox.Show(filename_noext, "Filename");
                // …
Run Code Online (Sandbox Code Playgroud)

c# openfiledialog visual-studio-2010 dialogresult winforms

3
推荐指数
1
解决办法
2万
查看次数