填充Property Grid Combobox [英] Populate Property Grid Combobox
问题描述
下午所有人,
我已经开始学习C#而且我遇到了一个使用属性网格的项目问题。我有一个16x16 png图像的目录。我的最终目标是使用文件名和图像填充组合框。
我看过几篇文章,其中包含静态值和列表,但我需要读取目录以获取文件名和图像。如果有人能帮助我走上正确的轨道,那就太好了。下面是我到目前为止编写的类,它将创建一个填充属性网格的对象。
Afternoon Everyone,
I have started learning C# and I'm running into an issue with my project that uses a property grid. I have a directory with 16x16 png images. My end goal is to populate a combobox with the file name and image.
I have looked at several articles that a being populated off static values and list but i would need to read a directory to get the file names and images. IF someone could help get me on the right track that would be great. Below is the class i have written so far that will create an object to populate a property grid.
using System;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.ComponentModel;
using System.Globalization;
using System.IO;
namespace PropertyGrid_Testing
{
class PG_Program
{
public object Action(string DisplayName, string Type, int Index, string Icon, string File, string Arguments)
{
Action MyWorker = new Action();
MyWorker.DisplayName = DisplayName;
MyWorker.Type = Type;
MyWorker.Index = Index;
MyWorker.Icon = Icon;
MyWorker.File = File;
MyWorker.Arguments = Arguments;
return MyWorker;
}
}
internal class Action
{
[Description("This is the Display Name used in the Context Menu.")]
[Category("Detials")]
public string DisplayName { get; set; }
[ReadOnly(true)]
[Description("This is the Type of item listed in the context menu. There can be Group, Action, or SEP. This setting gets set duing the new item creation.")]
[Category("Detials")]
public string Type { get; set; }
[Description("This is the index in wish you want the item to display.")]
[Category("Detials")]
public int Index { get; set; }
[Description("This is icon used to reference the context menu item.")]
[Category("Detials")]
public string Icon { get; set; }
[Description("This is item you wish to invoke. This can be anything, ex: exe, bat, png, xlsx...")]
[Category("Action")]
[BrowsableAttribute(true)]
[EditorAttribute(typeof(SaveFileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string File { get; set; }
[Description("(Optional) This references the arguments you wish to pass to the file you choose to invoke.")]
[Category("Action")]
public string Arguments { get; set; }
}
public class SaveFileNameEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (context == null || context.Instance == null || provider == null)
{
return base.EditValue(context, provider, value);
}
using (OpenFileDialog OFDialog = new OpenFileDialog())
{
if (value != null)
{
OFDialog.InitialDirectory = System.IO.Path.GetDirectoryName(value.ToString());
OFDialog.FileName = value.ToString();
}
OFDialog.Title = "Select Action Item";
OFDialog.Filter = "All files (*.*)|*.*";
if (OFDialog.ShowDialog() == DialogResult.OK)
{
value = OFDialog.FileName;
}
}
return value;
}
}
}
推荐答案
请参阅:
https://msdn.microsoft.com/ en-us / library / system.windows.forms.datagridviewcomboboxcell%28v = vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/b832b1w6%28v=vs。 110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridvi ewcomboboxcell.objectcollection%28v = vs.110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/0e66ystz(v=vs.110).aspx [ ^ ] ,
https://msdn.microsoft。 com / en-us / library / 7hsc9eaw(v = vs.110).aspx [ ^ ]。
有什么问题吗?
-SA
Please see:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcell%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/b832b1w6%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcell.objectcollection%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/0e66ystz(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/7hsc9eaw(v=vs.110).aspx[^].
Any problems?
—SA
这篇关于填充Property Grid Combobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!