日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > asp.net >内容正文

asp.net

WPFの操作文件浏览框几种方式

發(fā)布時(shí)間:2023/12/1 asp.net 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPFの操作文件浏览框几种方式 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
WPFの操作文件瀏覽框幾種方式 原文:WPFの操作文件瀏覽框幾種方式

方式1: 使用win32控件OpenFileDialog

Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.DefaultExt = ".xml"; ofd.Filter = "xml file|*.xml"; if (ofd.ShowDialog() == true) { //此處做你想做的事 ...=ofd.FileName; }

方式2: 使用Forms中的OpenFileDialog控件

WPF中是不能直接使用Forms中的控件的,否則會(huì)提示找不到Forms名字控件. 如果你仍然要用, 答案便是添加.net 引用reference

System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //此處做你想做的事 ...=openFileDialog1.FileName; }類(lèi)似的有文件夾瀏覽對(duì)話(huà)框: System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); System.Windows.Forms.DialogResult result = folderBrowserDialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK) { tb_FolderPath.Text = folderBrowserDialog.SelectedPath; }

方式三: 使用win32 api

BOOL WINAPI GetOpenFileName( __inout LPOPENFILENAME lpofn)

?

使用這種方式, 你需要自己實(shí)現(xiàn)LPOPENFILENAME結(jié)構(gòu)和對(duì)GetOpenFileName方法就行封裝:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public class OpenFileName { public int structSize = 0; public IntPtr hwnd = IntPtr.Zero; public IntPtr hinst = IntPtr.Zero; public string filter = null; public string custFilter = null; public int custFilterMax = 0; public int filterIndex = 0; public string file = null; public int maxFile = 0; public string fileTitle = null; public int maxFileTitle = 0; public string initialDir = null; public string title = null; public int flags = 0; public short fileOffset = 0; public short fileExtMax = 0; public string defExt = null; public int custData = 0; public IntPtr pHook = IntPtr.Zero; public string template = null; } public class LibWrap { // Declare a managed prototype for the unmanaged function. [DllImport("Comdlg32.dll",SetLastError=true,ThrowOnUnmappableChar=true, CharSet = CharSet.Auto)] public static extern bool GetOpenFileName([In, Out] OpenFileName ofn); }之后的工作就是實(shí)例化、初始化和方法調(diào)用了:123456789101112131415OpenFileName ofn = new OpenFileName(); ofn.structSize = Marshal.SizeOf(ofn); ofn.filter = "Project files\0*.xml"; ofn.file = new string(new char[256]); ofn.maxFile = ofn.file.Length; ofn.fileTitle = new string(new char[64]); ofn.maxFileTitle = ofn.fileTitle.Length; ofn.initialDir = "C:\\"; ofn.title = "Open Project"; ofn.defExt = "xml"; ofn.structSize = Marshal.SizeOf(ofn); if (LibWrap.GetOpenFileName(ofn)) { //此處做你想做的事 ...=ofn.file; }

?

posted on 2018-11-11 13:08 NET未來(lái)之路 閱讀(...) 評(píng)論(...) 編輯 收藏

轉(zhuǎn)載于:https://www.cnblogs.com/lonelyxmas/p/9941817.html

總結(jié)

以上是生活随笔為你收集整理的WPFの操作文件浏览框几种方式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。