- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
请注意这不是重复问题。
如何从 PropertyGrid 中显示详细的 FolderBrowser,如下图所示(来自带有省略号的字段/属性 ...)
使用
[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
[EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
我们得到了简约的文件夹浏览器
最佳答案
这是一个允许您使用 Vista 文件夹浏览器的自定义 UITypeEditor:
您可以像使用任何其他编辑器一样使用它:
[EditorAttribute(typeof(FolderNameEditor2), typeof(System.Drawing.Design.UITypeEditor))]
它依赖于我为此场合编写的自定义 FolderBrowser2 类。当然,这仅适用于 Windows Vista 及更高版本。在以前的 Windows 版本上,除了简单的文件夹浏览器外,没有其他文件夹浏览器。
public class FolderNameEditor2 : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
FolderBrowser2 browser = new FolderBrowser2();
if (value != null)
{
browser.DirectoryPath = string.Format("{0}", value);
}
if (browser.ShowDialog(null) == DialogResult.OK)
return browser.DirectoryPath;
return value;
}
}
public class FolderBrowser2
{
public string DirectoryPath { get; set; }
public DialogResult ShowDialog(IWin32Window owner)
{
IntPtr hwndOwner = owner != null ? owner.Handle : GetActiveWindow();
IFileOpenDialog dialog = (IFileOpenDialog)new FileOpenDialog();
try
{
IShellItem item;
if (!string.IsNullOrEmpty(DirectoryPath))
{
IntPtr idl;
uint atts = 0;
if (SHILCreateFromPath(DirectoryPath, out idl, ref atts) == 0)
{
if (SHCreateShellItem(IntPtr.Zero, IntPtr.Zero, idl, out item) == 0)
{
dialog.SetFolder(item);
}
Marshal.FreeCoTaskMem(idl);
}
}
dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM);
uint hr = dialog.Show(hwndOwner);
if (hr == ERROR_CANCELLED)
return DialogResult.Cancel;
if (hr != 0)
return DialogResult.Abort;
dialog.GetResult(out item);
string path;
item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out path);
DirectoryPath = path;
return DialogResult.OK;
}
finally
{
Marshal.ReleaseComObject(dialog);
}
}
[DllImport("shell32.dll")]
private static extern int SHILCreateFromPath([MarshalAs(UnmanagedType.LPWStr)] string pszPath, out IntPtr ppIdl, ref uint rgflnOut);
[DllImport("shell32.dll")]
private static extern int SHCreateShellItem(IntPtr pidlParent, IntPtr psfParent, IntPtr pidl, out IShellItem ppsi);
[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();
private const uint ERROR_CANCELLED = 0x800704C7;
[ComImport]
[Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")]
private class FileOpenDialog
{
}
[ComImport]
[Guid("42f85136-db7e-439c-85f1-e4075d135fc8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IFileOpenDialog
{
[PreserveSig]
uint Show([In] IntPtr parent); // IModalWindow
void SetFileTypes(); // not fully defined
void SetFileTypeIndex([In] uint iFileType);
void GetFileTypeIndex(out uint piFileType);
void Advise(); // not fully defined
void Unadvise();
void SetOptions([In] FOS fos);
void GetOptions(out FOS pfos);
void SetDefaultFolder(IShellItem psi);
void SetFolder(IShellItem psi);
void GetFolder(out IShellItem ppsi);
void GetCurrentSelection(out IShellItem ppsi);
void SetFileName([In, MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
void SetTitle([In, MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
void SetOkButtonLabel([In, MarshalAs(UnmanagedType.LPWStr)] string pszText);
void SetFileNameLabel([In, MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
void GetResult(out IShellItem ppsi);
void AddPlace(IShellItem psi, int alignment);
void SetDefaultExtension([In, MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
void Close(int hr);
void SetClientGuid(); // not fully defined
void ClearClientData();
void SetFilter([MarshalAs(UnmanagedType.Interface)] IntPtr pFilter);
void GetResults([MarshalAs(UnmanagedType.Interface)] out IntPtr ppenum); // not fully defined
void GetSelectedItems([MarshalAs(UnmanagedType.Interface)] out IntPtr ppsai); // not fully defined
}
[ComImport]
[Guid("43826D1E-E718-42EE-BC55-A1E261C37BFE")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IShellItem
{
void BindToHandler(); // not fully defined
void GetParent(); // not fully defined
void GetDisplayName([In] SIGDN sigdnName, [MarshalAs(UnmanagedType.LPWStr)] out string ppszName);
void GetAttributes(); // not fully defined
void Compare(); // not fully defined
}
private enum SIGDN : uint
{
SIGDN_DESKTOPABSOLUTEEDITING = 0x8004c000,
SIGDN_DESKTOPABSOLUTEPARSING = 0x80028000,
SIGDN_FILESYSPATH = 0x80058000,
SIGDN_NORMALDISPLAY = 0,
SIGDN_PARENTRELATIVE = 0x80080001,
SIGDN_PARENTRELATIVEEDITING = 0x80031001,
SIGDN_PARENTRELATIVEFORADDRESSBAR = 0x8007c001,
SIGDN_PARENTRELATIVEPARSING = 0x80018001,
SIGDN_URL = 0x80068000
}
[Flags]
private enum FOS
{
FOS_ALLNONSTORAGEITEMS = 0x80,
FOS_ALLOWMULTISELECT = 0x200,
FOS_CREATEPROMPT = 0x2000,
FOS_DEFAULTNOMINIMODE = 0x20000000,
FOS_DONTADDTORECENT = 0x2000000,
FOS_FILEMUSTEXIST = 0x1000,
FOS_FORCEFILESYSTEM = 0x40,
FOS_FORCESHOWHIDDEN = 0x10000000,
FOS_HIDEMRUPLACES = 0x20000,
FOS_HIDEPINNEDPLACES = 0x40000,
FOS_NOCHANGEDIR = 8,
FOS_NODEREFERENCELINKS = 0x100000,
FOS_NOREADONLYRETURN = 0x8000,
FOS_NOTESTFILECREATE = 0x10000,
FOS_NOVALIDATE = 0x100,
FOS_OVERWRITEPROMPT = 2,
FOS_PATHMUSTEXIST = 0x800,
FOS_PICKFOLDERS = 0x20,
FOS_SHAREAWARE = 0x4000,
FOS_STRICTFILETYPES = 4
}
}
关于c# - 从 PropertyGrid 显示详细的文件夹浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15368771/
我是C#/WPF的初学者,正在尝试使用Xceed PropertyGrid。在他们的网站上,他们显示了一个示例:
对 PropertyGrid 控件进行了一些运行,现在偶然发现了一个奇怪的问题。我在一个类中有一个 Uint32 属性,它是一个位掩码。因此,我决定创建一个带有 32 个按钮的自定义下拉 UserCo
我有一个项目,我们必须以所见即所得的方式在用户控件上表示一些图形对象。还需要编辑每个对象的属性(颜色、位置等)。 alt text http://lh6.ggpht.com/_1TPOP7DzY1E/
我正在使用 PropertyGrid (在 CollectionEditor 中)编辑类的一些属性。这些属性实际上包含在实现 ICustomTypeDescriptor 的类中。 .其中之一使用继承自
我见过的所有 PropertyGrid 示例都允许用户编辑单个对象,PropertyGrid 通过反射扫描该对象。我希望用户能够编辑一个 ini 文件或一本普通的字典,每个键值对一行。这可能吗? 最佳
有没有办法使 ExtJS4 PropertyGrid (Ext.grid.property.Grid) 不可编辑? 没有“可编辑”或“只读”配置选项 AFAICS。 最佳答案 另一种解决方案是添加一个
在 PropertyGrid 表单元素中,当我将属性添加到我的类别时,一些属性以粗体显示。 现在,我知道它表明它们是该类别中的默认值。我的问题是如何使所有属性不加粗? 我知道一种可能的方法是更改
我有: class Foo1 { private string name1; [CategoryAttribute("Category1")] public string Na
我有一个 PropertyGrid,我向其中添加了一个 bool 值数组。数组本身被标记为只读,属性网格可以正确识别它。 但是:如果我在网格中展开数组,所有项目都可以由用户编辑。当然那不是我想要的。如
我一直在研究 PropertyGrids,将它们链接到类,并试图弄清楚如何(如果可能)我可以显示一个类,在 扁平结构(好像它们都在一个类中) 我有几个类,Foo 和 Bar,如下所示: [Serial
在 C# 中,当使用对象具有 Collection 的 PropertyGrid 时,什么决定 DisplayName 旁边的值是否显示该值“(集合)”? 这个值是否有特定的属性? 谢谢 最佳答案 您
我在使用 propertygrid 时遇到了一些问题。即: 当我在 visual studio 设计器中使用 propertygrid 时,行为与在运行时以及调试时不同。 需要注意的几点(这是在设计器
我正在尝试使用 VS2005 (.NET 2.0) 在 C# 中实现对属性网格的拖放支持。 propertygrid 可以处理 dragenter 等事件,但似乎没有办法在拖动事件期间将 gridit
我正在使用 PropertyGrid 来显示通过实现 ICustomTypeDescriptor 公开的自定义属性。 我的对象设置在树结构中,每个属性的值要么在每个对象中设置,要么从父对象继承。在 P
是否可以在属性网格提示中添加可点击的超链接? 我的类(class)有以下内容(作为 SelectedObject 分配给属性网格): [Browsable(true), ReadOnly(false)
是否有一种简单的方法可以查明用户当前是否正在编辑属性网格? 我的用例如下:我每秒更新一次网格数据。如果用户正在编辑一个值,则在调用我的更新时所有输入都会丢失。所以我想做的是仅在用户未编辑内容时更新。
我有 类 PGMain 作为 propertygrid 中的 SelectedObject: [DefaultPropertyAttribute("Basic")] [Seriali
我有一个包含两个属性网格的表单。第一个网格的 SelectedObject 属性设置为包含 item 对象。而第二个设置为item.Test; public MainForm() { Init
我有一个 PropertyGrid。当我输入格式错误的值(即 - 将字符串转换为整数项)时,我收到一条错误消息。如果我单击“确定”,则错误值会一直存在,直到我更改它为止。如果我点击“取消”,原始值又回
在 C# (.Net 2.0) 的一个项目中,我使用了一个 propertygrid。此属性网格显示通过 SOAP 从 PHP 后端检索的对象。某些对象包含字符串属性,其中空字符串的含义与 NULL
我是一名优秀的程序员,十分优秀!