设计器中删除GenerateMember和Modifiers属性

设计器中删除GenerateMember和Modifiers属性

本文介绍了在设计器中删除GenerateMember和Modifiers属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Button后代,其中隐藏了所有不使用的属性.

I created a Button descendant where I hide all the properties I don't use.

我这样做是这样的:

[Browsable(false)]
[Bindable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Obsolete("", true)]
public new Boolean AllowDrop { get; set; }

大多数属性被正确隐藏,无法使用.

Most properties get correctly hidden and cannot be used.

但是,有两个属性我无法摆脱.

However there are two properties that I cannot get rid of.

是否可以在设计器中删除GenerateMember和Modifiers?

Is there a way to also remove GenerateMember and Modifiers in the Designer?

推荐答案

您可以创建一个新的 ControlDesigner 供您控制,并覆盖其 PostFilterProperties 方法.该方法使您可以更改或删除属性字典中的项目.

You can create a new ControlDesigner for your control and override its PostFilterProperties method. The method lets you to change or remove the items within the dictionary of properties.

属性字典中的键是属性的名称.尽管 ModifiersGenerateMember 不是控件的实际属性,它们是设计时属性,您仍然可以通过以下方式将其删除:

The keys in the dictionary of properties are the names of the properties. Although Modifiers and GenerateMember are not actual properties of your control and they are design-time properties, you can still remove them this way:

using System.Windows.Forms;
using System.Windows.Forms.Design;
[Designer(typeof(MyCustomControlDesigner))]
public class MyCustomControl:Button
{
}
public class MyCustomControlDesigner:ControlDesigner
{
   protected override void PostFilterProperties(System.Collections.IDictionary properties)
   {
       base.PostFilterProperties(properties);
       properties.Remove("Modifiers");
       properties.Remove("GenerateMember");
   }
}

要在属性网格中隐藏属性,您可以对它们执行相同的操作,而不是覆盖或阴影它们.

To hide properties in property grid, Instead of overriding or shadowing them, you can do the same thing for them.

这篇关于在设计器中删除GenerateMember和Modifiers属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:58