Do you encapsulate (aka lock) values of forms?
Updated by Brady Stroud [SSW] 1 year ago. See history
123
One useful feature of inherited forms is the ability to lock the value of certain properties on the inherited copy. E.g.:
- Font - we want to maintain a consistent font across all forms
- BackColor - changing the background color prevents the form from being themed
- Icon - we want all of our forms to have the company Icon
This can be achieved with the following code, which works by hiding the existing property from the designer using the Browsable attribute. The Browsable attribute set to False means "don't show in the the designer". There is also an attribute called EditorBrowsable, which hides the property from intellisense.
C#:
using System.ComponentModel;[Browsable(false)] // Browsable = show property in the Designerpublic new Font Font{get{return base.Font;}set{//base.Font = value; //normal property syntaxbase.Font = new Font("Tahoma", 8.25);// Must be hard coded - cannot use Me.}}
VB.NET:
Imports System.ComponentModel<Browsable(False)> _Public Shadows Property Font() As FontGetReturn MyBase.FontEnd GetSet(ByVal Value As Font)'MyBase.Font = Value 'normal property syntaxMyBase.Font = Me.FontEnd SetEnd Property

Figure: Font Property Visible

Figure: Font Property Hidden