我想單擊「瀏覽」按鈕時選擇本地硬盤上的文件。我不知道如何使用OpenFileDialog
控件。誰能幫我?如何使用C#將瀏覽文件按鈕添加到Windows窗體#
68
A
回答
86
這些鏈接舉例
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.
}
35
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
}
17
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 ;
}
在此代碼解釋它,你可以把你的地址在文本框中。
相關問題
- 1. 將文件瀏覽器按鈕添加到MS Access窗體
- 2. C#添加WPF按鈕到Windows窗體
- 3. 無法使用Windows窗體將操作添加到Visual Studio C++中的按鈕
- 4. 如何將瀏覽文件系統按鈕添加到Visual Studio應用程序?
- 5. C#將項添加到Windows窗體
- 6. 如何將動態按鈕及其事件添加到Windows窗體?
- 7. Windows窗體按鈕在C#
- 8. android如何添加瀏覽按鈕?
- 9. 如何將XML文件加載到集合C#Windows窗體
- 10. 添加單選按鈕到Windows窗體DataGrid控件
- 11. 將用戶控件添加到Windows窗體c時出錯#
- 12. 如何添加電子郵件預覽按鈕到MS-Access 2003中的窗體
- 13. 如何將oAuth(DevDefined oAuth)添加到C#windows窗體項目中?
- 14. 在visual C++窗體窗體應用程序中瀏覽文件
- 15. Windows窗體瀏覽器骨架(C#/。NET)
- 16. 如何使用按鈕單擊繪圖 - C++ Windows窗體
- 17. 如何在Windows窗體中動態添加單選按鈕?
- 18. 將Web窗體控件添加到Windows窗體
- 19. 如何使用ActionListener將JPanel窗體添加到JFrame窗體?
- 20. c#windows phone 8如何將樣式添加到按鈕
- 21. C#Windows窗體代碼不工作 - 將事件附加到按鈕
- 22. 如何將xaml頁面/ usercontrol添加到Windows窗體控件?
- 23. 如何將許多控件添加到Windows窗體選項卡?
- 24. 如何將文本添加到按鈕?
- 25. GWT:將窗口小部件添加到新窗口瀏覽器
- 26. 如何將System.Web引用添加到Windows窗體應用程序
- 27. 如何將Firefox和Chrome添加到C#瀏覽器控件?
- 28. 將按鈕添加到Visual Studio 2010中的Windows窗體應用程序
- 29. 瀏覽器使用C#在Windows窗體應用程序
- 30. 如何使用selenium webdriver處理Windows文件瀏覽窗口
非常感謝你的快速回復....它幫了我很多.. – Harikasai 2011-02-16 04:34:41