gpt4 book ai didi

c# - 如何从 C# 显示文件的属性对话框?

转载 作者:可可西里 更新时间:2023-11-01 10:41:02 26 4
gpt4 key购买 nike

如何通过按钮打开文件的属性对话框

private void button_Click(object sender, EventArgs e)
{
string path = @"C:\Users\test\Documents\tes.text";
// how to open this propertie
}

谢谢。

例如,如果想要系统属性

Process.Start("sysdm.cpl");    

但是如何获取文件路径的“属性”对话框?

最佳答案

解决方法是:

using System.Runtime.InteropServices;

[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHELLEXECUTEINFO
{
public int cbSize;
public uint fMask;
public IntPtr hwnd;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpVerb;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpFile;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpParameters;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpDirectory;
public int nShow;
public IntPtr hInstApp;
public IntPtr lpIDList;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpClass;
public IntPtr hkeyClass;
public uint dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}

private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;
public static bool ShowFileProperties(string Filename)
{
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpVerb = "properties";
info.lpFile = Filename;
info.nShow = SW_SHOW;
info.fMask = SEE_MASK_INVOKEIDLIST;
return ShellExecuteEx(ref info);
}

// button click
private void button1_Click(object sender, EventArgs e)
{
string path = @"C:\Users\test\Documents\test.text";
ShowFileProperties(path);
}

关于c# - 如何从 C# 显示文件的属性对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57610477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com