<i id='io4ea'><tr id='io4ea'><dt id='io4ea'><q id='io4ea'><span id='io4ea'><b id='io4ea'><form id='io4ea'><ins id='io4ea'></ins><ul id='io4ea'></ul><sub id='io4ea'></sub></form><legend id='io4ea'></legend><bdo id='io4ea'><pre id='io4ea'><center id='io4ea'></center></pre></bdo></b><th id='io4ea'></th></span></q></dt></tr></i><div id='io4ea'><tfoot id='io4ea'></tfoot><dl id='io4ea'><fieldset id='io4ea'></fieldset></dl></div>

      1. <legend id='io4ea'><style id='io4ea'><dir id='io4ea'><q id='io4ea'></q></dir></style></legend>

        <small id='io4ea'></small><noframes id='io4ea'>

          <bdo id='io4ea'></bdo><ul id='io4ea'></ul>

        <tfoot id='io4ea'></tfoot>

        设计时表单的自定义可浏览属性

        Custom browsable property for Form at design time(设计时表单的自定义可浏览属性)
          <bdo id='GZYDX'></bdo><ul id='GZYDX'></ul>
          1. <small id='GZYDX'></small><noframes id='GZYDX'>

            <i id='GZYDX'><tr id='GZYDX'><dt id='GZYDX'><q id='GZYDX'><span id='GZYDX'><b id='GZYDX'><form id='GZYDX'><ins id='GZYDX'></ins><ul id='GZYDX'></ul><sub id='GZYDX'></sub></form><legend id='GZYDX'></legend><bdo id='GZYDX'><pre id='GZYDX'><center id='GZYDX'></center></pre></bdo></b><th id='GZYDX'></th></span></q></dt></tr></i><div id='GZYDX'><tfoot id='GZYDX'></tfoot><dl id='GZYDX'><fieldset id='GZYDX'></fieldset></dl></div>

                <tbody id='GZYDX'></tbody>
                <legend id='GZYDX'><style id='GZYDX'><dir id='GZYDX'><q id='GZYDX'></q></dir></style></legend>
                <tfoot id='GZYDX'></tfoot>
                • 本文介绍了设计时表单的自定义可浏览属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在设计时为可浏览的 Windows 窗体创建一个自定义属性,但我的努力都没有成功.显而易见的解决方案似乎是将 browsable 属性设置为 true:

                  I want to make a custom property for a windows form browsable during design-time but none of my efforts have panned out to success. The obvious solution would seem to be to set the browsable attribute to true:

                  [Browsable(true),
                  EditorBrowsable(EditorBrowsableState.Always),
                  Description("Custom Border Colour"),
                  Category("Custom")]
                  public Color BorderColour
                  {
                      get
                      {
                          return bCol;
                      }
                      set
                      {
                          bCol = value;
                      }
                  }
                  

                  但这不起作用.我已经为自定义控件做了很多次,它就像一个魅力,事实上,我什至不需要添加属性,因为默认值为 true.这个 codeproject 文章似乎做了我想要,这就是我上面描述的.MSDN也是死路一条,还是不知道要找什么.

                  But this doesn't work. I have done it numerous time for custom controls and it works like a charm, in fact, I don't even need to add the attributes because the default is true. This codeproject article seems to do what I want, which is what I described above. MSDN is also a dead end, or I don't know what to search for.

                  我尝试将代码添加到 Form1.csFrom1.Designer.cs 但没有任何效果.

                  I have tried to add the code to Form1.cs and From1.Designer.cs but nothing works.

                  我是否缺少某些东西,例如我需要为表单设置的某些属性以允许这样做,或者这是不可能的?

                  Is there something I am missing, like some property I need to set for the form to allow for this, or is it just impossible?

                  我正在使用 Visual Studio Express 2013,如果这会以任何方式影响结果.

                  I am using Visual Studio Express 2013, if this would influence the outcomes in any way.

                  Reza 回答后的尝试:这个问题.

                  推荐答案

                  简答

                  您应该将该属性添加到表单的基类中,然后您可以在打开子表单时在设计器中看到它:

                  You should add the property to base class of your form, then you can see it in designer when you open the child form:

                  public class Form1 : BaseForm
                  {
                      public Form1()
                      {
                          InitializeComponent();
                      }
                  }
                  

                  public class BaseForm : Form
                  {
                      //The property is not visible in designer of BaseForm
                      //But you can see it in designer of Form1
                  
                      public string SomeProperty {get;set;}
                  }
                  

                  这种行为背后的原因

                  原因在于设计师的工作方式.当设计者在设计时显示一个表单时,实际上它创建了一个表单基类的实例并显示了它的属性.因此,在设计器中拥有 public class Form1:Form,您在设计器中看到的实际上是 Form 类的一个实例,以及使用 using 设置了哪些属性值的控件的实例Form1InitializeComponent 方法以及使用 Form1InitializeComponent 方法添加的控件.

                  The reason is in the way that designer works. When the designer shows a form at design time, in fact it creates an instance of the base class of the form and shows its properties. So having public class Form1:Form in designer, what you see in designer is actually an instance of Form class and the instances of controls which values of properties has been set using using InitializeComponent method of Form1 and also controls which are added using InitializeComponent method of Form1.

                  同样对于用户控件,您无法在用户控件的设计器中看到您的自定义属性,因为您可以在用户控件的设计器中看到的属性是其基类的属性.但是,当您将用户控件的实例放在表单上时,您会看到该实例的属性,即 UserControl1 的属性.

                  Also for user controls, you can not see your custom properties in the designer of your user control, because the properties that you can see in designer of your user control, is properties of it's base class. But when you put an instance of your user control on a form, you will see properties of that instance which is properties of your UserControl1.

                  设计器的根元素的属性是根元素的基类的属性.但这些值正是 InitializeComponent 中设置的值.

                  Properties of the root element of your designer are properties of base class of the root element. But the values are exactly those which are set in InitializeComponent.

                  要查找更多信息并查看设计师如何工作的有趣示例,您可以查看此帖子或这个.

                  To find more information and see an interesting example of how the designer works, you can take a look at this post or this one.

                  这篇关于设计时表单的自定义可浏览属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)

                  <small id='elCmm'></small><noframes id='elCmm'>

                  <legend id='elCmm'><style id='elCmm'><dir id='elCmm'><q id='elCmm'></q></dir></style></legend>
                  1. <tfoot id='elCmm'></tfoot>
                        <tbody id='elCmm'></tbody>

                      • <i id='elCmm'><tr id='elCmm'><dt id='elCmm'><q id='elCmm'><span id='elCmm'><b id='elCmm'><form id='elCmm'><ins id='elCmm'></ins><ul id='elCmm'></ul><sub id='elCmm'></sub></form><legend id='elCmm'></legend><bdo id='elCmm'><pre id='elCmm'><center id='elCmm'></center></pre></bdo></b><th id='elCmm'></th></span></q></dt></tr></i><div id='elCmm'><tfoot id='elCmm'></tfoot><dl id='elCmm'><fieldset id='elCmm'></fieldset></dl></div>
                          <bdo id='elCmm'></bdo><ul id='elCmm'></ul>