OpenFileDialog 상자를 취소 할 때가 언제입니까? 그것의 오류 경로를주는 것은 비어 있습니다. 내 OpenFileDialog를 상자 https://imageshack.com/i/iqQYnD8pjOpenFileDialog 상자에서 취소 단추를 코딩하는 방법
내가 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");
// MessageBox.Show(full_path, "path");
//move file from location to debug
string replacepath = @"E:\Debug";
string fileName = System.IO.Path.GetFileName(path);
string newpath = System.IO.Path.Combine(replacepath, fileName);
if (!System.IO.File.Exists(filename_noext))
System.IO.File.Copy(path, newpath);
}
//tried using below codes but not taking return statement. saying "An object of a type convertible to 'string' is required"
if (ofd.ShowDialog() != DialogResult.OK)
return;//---->> here its not taking return
//when ever i press the cancel or close button it is going to below line. How to stop this
StreamReader test2 = new StreamReader(img_path.Text);
string s = test2.ReadToEnd();
return s;
}
private string Print_image()
{
//some codes that returns string value in s
return s;
}
, 내가 그것을 선으로가는 취소를 누르면 '에서는 StreamReader TEST2 = 새에서는 StreamReader (img_path.Text) ; ' 내가 어떤 파일을 선택하지 않았다면 그것을 막는 방법 –
@Shell 어떤 도움 /// –