文档彩票走势图>>DevExpress WinForm中文手册>>文件和文件夹浏览器
文件和文件夹浏览器
DevExpress WinForms安装附带了两个文件和文件夹浏览器选项:
XtraOpenFileDialog、XtraSaveFileDialog和XtraFolderBrowserDialog类实例取代了标准的Windows“Save As”、“Open”和“Browse For Folder”对话框。DevExpress对话框支持Windows Vista和更新的操作系统。
提示:要强制所有DevExpress控件和组件使用额外的对话框而不是标准的对话框,启用WindowsFormsSettings.UseDXDialogs 属性。
可显示为模态对话框或嵌入到表单或用户控件中的自定义文件夹浏览器,要创建这样的浏览器,请使用FileExplorerAssistant组件。
如何显示XtraSaveFileDialog
下面的示例演示如何显示XtraSaveFileDialog。
C#:
using System.IO; private void simpleButtonSaveFileDialog_Click(object sender, EventArgs e) { Stream memoStream; xtraSaveFileDialog1.Filter = "txt files (*.txt)|*.txt"; if(xtraSaveFileDialog1.ShowDialog() == DialogResult.OK) { if((memoStream = xtraSaveFileDialog1.OpenFile()) != null) { // Code to write the stream goes here. memoStream.Close(); } } }
点击复制
VB.NET:
Imports System.IO Private Sub simpleButtonSaveFileDialog_Click(ByVal sender As Object, ByVal e As EventArgs) Dim memoStream As Stream xtraSaveFileDialog1.Filter = "txt files (*.txt)|*.txt" If xtraSaveFileDialog1.ShowDialog() = DialogResult.OK Then memoStream = xtraSaveFileDialog1.OpenFile() If memoStream IsNot Nothing Then ' Code to write the stream goes here. memoStream.Close() End If End If End Sub
点击复制
如何显示XtraOpenFileDialog
下面的示例演示如何显示XtraOpenFileDialog。
C#:
using System.IO; private void simpleButtonOpenFileDialog_Click(object sender, EventArgs e) { xtraOpenFileDialog1.InitialDirectory = "c:\\"; xtraOpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; if(xtraOpenFileDialog1.ShowDialog() == DialogResult.OK) { // Get the path of specified file. string filePath = xtraOpenFileDialog1.FileName; // Read the contents of the file into a stream. var fileStream = xtraOpenFileDialog1.OpenFile(); using(StreamReader reader = new StreamReader(fileStream)) { // ... } } }
点击复制
VB.NET:
Imports System.IO Private Sub simpleButtonOpenFileDialog_Click(ByVal sender As Object, ByVal e As EventArgs) xtraOpenFileDialog1.InitialDirectory = "c:\" xtraOpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" If xtraOpenFileDialog1.ShowDialog() = DialogResult.OK Then ' Get the path of specified file. Dim filePath As String = xtraOpenFileDialog1.FileName ' Read the contents of the file into a stream. Dim fileStream = xtraOpenFileDialog1.OpenFile() Using reader As New StreamReader(fileStream) ' ... End Using End If End Sub
点击复制