반응형
C #을 사용하여 Windows Form에 파일 찾아보기 단추를 추가하는 방법
"찾아보기"버튼을 클릭 할 때 로컬 하드 디스크에있는 파일을 선택하고 싶습니다.
OpenFileDialog
컨트롤 을 사용하는 방법을 모르겠습니다 . 누구든지 나를 도울 수 있습니까?
이 링크는 예제와 함께 설명합니다.
http://dotnetperls.com/openfiledialog
http://www.geekpedia.com/tutorial67_Using-OpenFileDialog-to-open-files.html
private void button1_Click(object sender, EventArgs e)
{
int size = -1;
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
try
{
string text = File.ReadAllText(file);
size = text.Length;
}
catch (IOException)
{
}
}
Console.WriteLine(size); // <-- Shows file size in debugging mode.
Console.WriteLine(result); // <-- For debugging use.
}
var FD = new System.Windows.Forms.OpenFileDialog();
if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
string fileToOpen = FD.FileName;
System.IO.FileInfo File = new System.IO.FileInfo(FD.FileName);
//OR
System.IO.StreamReader reader = new System.IO.StreamReader(fileToOpen);
//etc
}
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "C# Corner Open File Dialog" ;
fdlg.InitialDirectory = @"c:\" ;
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ;
fdlg.FilterIndex = 2 ;
fdlg.RestoreDirectory = true ;
if(fdlg.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fdlg.FileName ;
}
이 코드에서 텍스트 상자에 주소를 입력 할 수 있습니다.
반응형
'program story' 카테고리의 다른 글
Phonegap 프로젝트에 앱 아이콘을 추가하는 방법은 무엇입니까? (0) | 2020.09.16 |
---|---|
구성 요소 외부에있는 클릭 이벤트를 수신하는 방법 (0) | 2020.09.16 |
Java 7 try-with-resources를 올바르게 사용하고 있습니까? (0) | 2020.09.16 |
MongoDB에서 '좋지 않음'연산자를 어떻게 사용할 수 있습니까? (0) | 2020.09.16 |
Ruby는 기능적인 언어입니까? (0) | 2020.09.16 |