如何让一个类的英文属性名在PropertyGrid中用中文显示出来?

12345678922222 2005-07-14 04:22:34
如何让一个类的英文属性名在PropertyGrid中用中文显示出来?
...全文
1161 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujiwe79 2005-12-12
  • 打赏
  • 举报
回复
我是专门做控件的,这个我已经完成,我写了一个特性dll,引用后,直接用特性类的名字就可以了,比如
/// <summary>
/// 控件的高度
/// </summary>
[Browsable(true)]
[DisplayName("高度"),Description("控件的高度")]
public new int Height
{
get
{
return base.Height;
}
set
{
base.Height = value;
}
}
有要这个dll的朋友,请qq283840698交流呀
cgsw12345 2005-12-12
  • 打赏
  • 举报
回复
http://www.codeproject.com/csharp/wdzPropertyGridUtils.asp#xx1297612xx
greennetboy 2005-11-01
  • 打赏
  • 举报
回复
我用一个思路:从System.ComponentModel.PropertyDescriptor继承自己的类,然后
从在DisplayName,在里面实现一个查表功能,使对应的英文名返回中文。最后要把PropertyGrid.SelectObject所选的对象从ICustomTypeDescriptor继承,并在其中的GetProperties中构造自己的PropertyDescriptorCollection用于返回。
------------------------------------------------------------------
我觉得这种方法可以考虑,建立一个Hashtable获得NameValuCollection用来维护中文和英文之间的映射,然后按照上述办法,不知道可行么?
搂主可尝试下!
LJ116 2005-11-01
  • 打赏
  • 举报
回复
我要哦,给我一份吧,mazha718@163.com,谢谢哦
liujiwe79 2005-10-17
  • 打赏
  • 举报
回复
这个要求很正常的,我最近在做一个开发平台,把.net带的所有控件全部都封装到我的平台上,属性全部都是中文的,我已经写好了一个dll,引用一下就可以了,有要的吗?
zhy0101 2005-10-14
  • 打赏
  • 举报
回复
好奇怪的要求
AManWanttoMarriage 2005-10-13
  • 打赏
  • 举报
回复
我用一个思路:从System.ComponentModel.PropertyDescriptor继承自己的类,然后
从在DisplayName,在里面实现一个查表功能,使对应的英文名返回中文。最后要把PropertyGrid.SelectObject所选的对象从ICustomTypeDescriptor继承,并在其中的GetProperties中构造自己的PropertyDescriptorCollection用于返回。
sunbin6ji 2005-10-13
  • 打赏
  • 举报
回复
MARK
sunbin6ji 2005-10-13
  • 打赏
  • 举报
回复
MARK
12345678922222 2005-07-15
  • 打赏
  • 举报
回复
今天接着来....
12345678922222 2005-07-15
  • 打赏
  • 举报
回复
下班前看一下
12345678922222 2005-07-14
  • 打赏
  • 举报
回复
努力....
zeusvenus 2005-07-14
  • 打赏
  • 举报
回复
.NETFRAMEWORK1.1不行,楼主这个可能不好实现,因为C#是类型安全的。
12345678922222 2005-07-14
  • 打赏
  • 举报
回复
是吗?.net2.0有这个功能,下载一个DEMO下来看看,谢谢楼上MVP。其它人有没有什么好的建议,让我们自己来实现这个功能的,而不是等微软来提供。我们不要总跟着别人后面嘛!
速马 2005-07-14
  • 打赏
  • 举报
回复
到了.NET 2.0有提供了一个DisplayName特性
比如:
[DisplayName("姓名")]
public string Name
{
get{return "";}
}

1.x的不支持这种功能
12345678922222 2005-07-14
  • 打赏
  • 举报
回复
楼上的,[Description("设置直线颜色"),Category("外观")]只能让PropertyGrid显示说明,不能把类的属性名汉化
dasanhai 2005-07-14
  • 打赏
  • 举报
回复
如下:

[Description("设置直线颜色"),Category("外观")]
public Color Color
{
get{ return _Color; }
set{ _Color = value; }
}
12345678922222 2005-07-14
  • 打赏
  • 举报
回复
楼上的,[Description("设置直线颜色"),Category("外观")]只能让PropertyGrid显示说明,不能把类的属性名汉化
dasanhai 2005-07-14
  • 打赏
  • 举报
回复
如下:

[System.Xml.Serialization.XmlIgnore]
[Description("设置直线颜色"),Category("外观")]
public Color Color
{
get{ return _Color; }
set{ _Color = value; refresh(); }
}
12345678922222 2005-07-14
  • 打赏
  • 举报
回复
我曾经的一个思路,中间有错误,未能完全满足要求
public class CheckUserInfoConverter : TypeConverter
{
  public CheckUserInfoConverter()  {}
  public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues)
  {
return new CheckUserInfoState();
  }
  public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
  {
PropertyDescriptorCollection collection1 = TypeDescriptor.GetProperties(typeof(CheckUserInfoState), attributes);
PropertyDescriptor[] pds = new PropertyDescriptor[collection1.Count + 1]; ArrayList list = new ArrayList();
foreach(PropertyDescriptor pd in collection1)
{
       Attribute[] Attributes = Attribute.GetCustomAttributes(GetPropertyInfo(pd.Name));
       foreach(Attribute a in Attributes)
  {
    if (a.GetType() == typeof(PropertyNameAttribute))
    {
  PropertyDescriptor m_pd = (PropertyDescriptor)TypeDescriptor.CreateProperty(typeof(CheckUserInfoState),((PropertyNameAttribute)a).Name,pd.PropertyType,new Attribute[] {(PropertyNameAttribute)a});          m_pd.SetValue(typeof(CheckUserInfoState),pd.GetValue(typeof(CheckUserInfoState)));
  list.Add(m_pd);
}
   }

for(int i = 0; collection1.Count > i; i++)
  pds[i] = (PropertyDescriptor)collection1[i];
pds[pds.Length - 1] = (PropertyDescriptor)list[0];
collection1 = new PropertyDescriptorCollection(pds);
return collection1;
   }
   private PropertyInfo GetPropertyInfo(string PropertyName)
   {
Type t = typeof(CheckUserInfoState);
foreach(PropertyInfo p in t.GetProperties())
{
   if (p.Name == PropertyName)
return p;
}
return null;
   }
   public override bool GetPropertiesSupported(ITypeDescriptorContext context)
   {
return true;
   }
}
加载更多回复(5)

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧