当前位置:网站首页>18. Opening and saving file dialog box usage notes
18. Opening and saving file dialog box usage notes
2022-07-26 23:31:00 【komla168】
Preface : Open the dialog box 、 The save dialog box is often used by desktop software , But the author recently found that the same name API There are different namespaces , Now record .
One 、 Official website API
1.1 System.Windows.Forms
OpenFileDialog and SaveFileDialog These two dialog boxes first appeared in System.Windows.Forms Under the namespace , With .Net Framwork1.1 The version came out . And they also quote System.ComponentModel Namespace .


1.2 Microsoft.Win32
And in Microsoft.Win32 Under the OpenFileDialog and SaveFileDialog The function is in .Net Framwork3.0 That's what happened , and Microsoft.Win32 Application programming interface (API) Is used for win32 A series of interface development programs .


Two 、 usage
It's almost the same , Just reference the corresponding namespace , One of the differences I encountered when using is ShowDialog() The return type of .


The referenced namespace is Microsoft.Win32
/// <summary>
/// 220723 komla File selection dialog
/// </summary>
void SelectFileDialog()
{
OpenFileDialog fie = new OpenFileDialog();
// Create objects
fie.Title = " Upload your avatar ";
// Set text box title
fie.InitialDirectory = @"C:\Users\Administrator\Desktop";
// The initial directory of the dialog
fie.Filter = " image file |*.jpg*| image file |*.png| All the files |*.*";
// Set file type
string str = fie.FileName;
// Get the path of choice
if (fie.ShowDialog() == true)
{
MessageBox.Show(fie.FileName);
// The user clicks open Code to hold the lamp after
}
}
/// <summary>
/// 220723 komla File Save dialog
/// </summary>
void SaveFileDialog()
{
SaveFileDialog s = new SaveFileDialog();
// Create objects
s.Filter = " image file |*.jpg| image file |*.png| All the files |*.*";
// Saved file extension
s.Title = " Save the file ";
// Dialog title
s.DefaultExt = " image file |*.jpg";
// Set the default file extension
// string str = s.DefaultExt;
// Get the file default extension
s.InitialDirectory = @"C:\Users\Administrator\Desktop";
// Set the initial directory for saving
if (s.ShowDialog() == true)
{
// The user clicks " preservation " Code executed after
}
string str = s.FileName;
// Get the directory saved by the user
}If quoted System.Windows.Forms Namespace only needs to be ShowDialog() To change the value of DialogResult.OK
if (s.ShowDialog() == DialogResult.OK)
{
// The user clicks " preservation " Code executed after
}3、 ... and 、 Citations
3.2 OpenFileDialog class (System.Windows.Forms) | Microsoft Docs
边栏推荐
- Vit:vision transformer super detailed with code
- 第二部分—C语言提高篇_8. 文件操作
- 基本的SELECT语句
- Hcia-r & s self use notes (23) DHCP
- 杭州银行面试题【杭州多测师】【杭州多测师_王sir】
- gateway基本使用
- Cheaper than seals, with a large space for shape explosion. Is there really no match for 200000 or so? Chang'an's new "King fried" is cost-effective
- HCIA-R&S自用笔记(20)VLAN综合实验、GVRP
- Recruit | PostgreSQL database R & D engineers every week, with an annual salary of 60+, high salary for famous enterprises, and challenge yourself!
- 2. Realize the map of navigation bar and battle page
猜你喜欢

基本的SELECT语句

Part II - C language improvement_ 6. Multidimensional array

Hcia-r & s self use notes (18) campus network architecture foundation, switch working principle, VLAN principle

程序员成长第二十九篇:如何激励员工?

百度网址收录

Part II - C language improvement_ 12. Packaging and use of dynamic / precision Library

1. Configuration environment and project creation

Esmfold: a new breakthrough in protein structure prediction after alphafold2

Basic use of gateway

json格式化小工具--pyqt5实例
随机推荐
第二部分—C语言提高篇_5. 位运算
Database full stack Engineers (devdbops) have low down payment and high return, and pay after employment
Typescript notes
华裔科学家Ashe教授对涉嫌造假的Nature论文的正面回应
Programmer growth chapter 29: how to motivate employees?
杭州银行面试题【杭州多测师】【杭州多测师_王sir】
【flask高级】结合源码分析flask中的线程隔离机制
Several inventory terms often used in communication
HCIA-R&S自用笔记(19)VLAN配置及实验、VLAN间路由
程序员成长第二十九篇:如何激励员工?
[shader realizes swaying effect _shader effect Chapter 4]
[flask advanced] analyze the thread isolation mechanism in flask in combination with the source code
np.transpose & np.expand_dims
如何使用数据管道实现测试现代化
实战项目:Boost搜索引擎
HCIA-R&S自用笔记(23)DHCP
Typescript stage learning
第二部分—C语言提高篇_8. 文件操作
第二部分—C语言提高篇_6. 多维数组
What is Base64?