menu

WinForms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class GridStyleInfoCustomProperties - WindowsForms API Reference | Syncfusion

    Show / Hide Table of Contents

    Class GridStyleInfoCustomProperties

    Provides a base class that you should derive from if you want to register additional custom properties with GridStyleInfo. Custom properties will be shown in the property grid for a style just like all other regular properties. You can also add expandable objects such as a font. Custom properties participate in the style inheritance mechanism similar to regular properties.

    Inheritance
    System.Object
    GridStyleInfoCustomProperties
    ButtonEditStyleProperties
    FloatNumericUpDownStyleProperties
    PictureBoxStyleProperties
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Syncfusion.Windows.Forms.Grid
    Assembly: Syncfusion.Grid.Windows.dll
    Syntax
    public class GridStyleInfoCustomProperties
    Examples

    See the following code samples how to get / set custom properties and a derived class with custom properties:

    GridControl grid = new GridControl();
    GridStyleInfo style = new GridStyleInfo();
    

    // using ctor with existing style object and caching the object (both C# and VB) MyCustomStyleProperties mcs = new MyCustomStyleProperties(style); mcs.TheLocked = true; mcs.TheFont.Bold = true;

    // design time code (both C# and VB) MyCustomStyleProperties myCustomStyleProperties1 = new MyCustomStyleProperties(); myCustomStyleProperties1.TheLocked = true; myCustomStyleProperties1.TheFont.Bold = true; style.CustomProperties.Add(myCustomStyleProperties1);

    // using ctor with indexer (C# only) (new MyCustomStyleProperties(grid[1,1])).TheLocked = true; (new MyCustomStyleProperties(grid[1,1])).TheFont.Bold = true;

    // using ctor with existing style object (C# only) style.Text = "bla"; new MyCustomStyleProperties(style).TheLocked = true; new MyCustomStyleProperties(style).TheFont.Bold = true;

    // explicit case (C# only) ((MyCustomStyleProperties) style).TheLocked = true; ((MyCustomStyleProperties) style).TheFont.Bold = true;

    Dim style As New GridStyleInfo()
    Dim grid As New GridControl()
    

    ' using ctor with existing style object and caching the object (VB and C#) Dim mcs As New MyCustomStyleProperties(style) mcs.TheLocked = True mcs.TheFont.Bold = True

    ' design time code (VB and C#) Dim myCustomStyleProperties1 As New MyCustomStyleProperties() myCustomStyleProperties1.TheLocked = True myCustomStyleProperties1.TheFont.Bold = True style.CustomProperties.Add(myCustomStyleProperties1)

    ' with operator (Visual Basic only) With New MyCustomStyleProperties(style) .TheLocked = True .TheFont.Bold = True End With

    ' with operator (Visual Basic only) With New MyCustomStyleProperties(grid(1, 1)) .TheLocked = True .TheFont.Bold = True End With

    using System;
    using System.ComponentModel;
    

    using Syncfusion.Diagnostics; using Syncfusion.Styles; using Syncfusion.Windows.Forms; using Syncfusion.Windows.Forms.Grid;

    namespace WindowsApplication1 { public class MyCustomStyleProperties : GridStyleInfoCustomProperties { // static initialization of property descriptors static Type t = typeof(MyCustomStyleProperties);

    readonly static StyleInfoProperty LockedProperty = CreateStyleInfoProperty(t, "TheLocked"); readonly static StyleInfoProperty TheFontProperty = CreateStyleInfoProperty(t, "TheFont");

    // default settings for all properties this object holds static MyCustomStyleProperties defaultObject;

    // initialize default settings for all properties in static ctor static MyCustomStyleProperties () { // all properties must be initialized for the Default property defaultObject = new MyCustomStyleProperties(GridStyleInfo.Default); defaultObject.TheLocked = true; defaultObject.TheFont = GridFontInfo.Default; }

    ///

    /// Provides access to default values for this type. /// public static MyCustomStyleProperties Default { get { return defaultObject; } }

    ///

    /// Force static ctor being called at least once. /// public static void Initialize() { }

    // Explicit cast from GridStyleInfo to MyCustomStyleProperties. // (Note: this will only work for C#, Visual Basic does not support dynamic casts.)

    ///

    /// Explicit cast from GridStyleInfo to this custom property object. /// /// A new custom properties object. public static explicit operator MyCustomStyleProperties(GridStyleInfo style) { return new MyCustomStyleProperties(style); }

    ///

    /// Initializes a MyCustomStyleProperties object with a style object that holds all data. /// public MyCustomStyleProperties(GridStyleInfo style) : base(style) { }

    ///

    /// Initializes a MyCustomStyleProperties object with an empty style object. Design- /// time environment will use this ctor and later copy the values to a style object /// by calling style.CustomProperties.Add(otherCustomStyleProperties1). /// public MyCustomStyleProperties() : base() { }

    ///

    /// Gets / sets TheLocked state. /// [ Description("Specifies if ..."), Browsable(true), Category("StyleCategoryBehavior") ] public bool TheLocked { get { TraceUtil.TraceCurrentMethodInfo(); return (bool) style.GetValue(LockedProperty); } set { TraceUtil.TraceCurrentMethodInfo(value); style.SetValue(LockedProperty, value); } } /// /// Resets TheLocked state. /// public void ResetTheLocked() { style.ResetValue(LockedProperty); } [EditorBrowsableAttribute(EditorBrowsableState.Never)] private bool ShouldSerializeTheLocked() { return style.HasValue(LockedProperty); } /// /// Gets if TheLocked state has been initialized for the current object. /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool HasTheLocked { get { return style.HasValue(LockedProperty); } }

    ///

    /// Gets / sets TheFont state. TheFont is itself an expandable object /// with several properties that can be set individually and participate /// in style inheritance mechanism. /// [ Description("The font for drawing text."), Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("StyleCategoryAppearance") ] public GridFontInfo TheFont { get { return (GridFontInfo) style.GetValue(TheFontProperty); } set { style.SetValue(TheFontProperty, value); } }

    ///

    /// Resets TheFont state. /// public void ResetTheFont() { style.ResetValue(TheFontProperty); } [EditorBrowsableAttribute(EditorBrowsableState.Never)] private bool ShouldSerializeTheFont() { return style.HasValue(TheFontProperty); } /// /// Determines if TheFont state has been initialized for the current object. /// [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool HasTheFont { get { return style.HasValue(TheFontProperty); } }

    }

    public class MyGridControl : GridControl { public MyGridControl() { // force static ctor of MyCustomStyleProperties being called at least once MyCustomStyleProperties.Initialize(); } } }

    Public Class MyCustomStyleProperties
        Inherits GridStyleInfoCustomProperties
        ' static initialization of property descriptors
        Private Shared t As Type = GetType(MyCustomStyleProperties)
    

    Private Shared LockedProperty As StyleInfoProperty = CreateStyleInfoProperty(t, "TheLocked") Private Shared TheFontProperty As StyleInfoProperty = CreateStyleInfoProperty(t, "TheFont")

    ' default settings for all properties this object holds Private Shared defaultObject As MyCustomStyleProperties

    ' initialize default settings for all properties in static ctor Shared Sub New() ' all properties must be initialized for the Default property defaultObject = New MyCustomStyleProperties(GridStyleInfo.Default) defaultObject.TheLocked = True defaultObject.TheFont = GridFontInfo.Default End Sub 'New

    '/

    '/ Provides access to default values for this type '/

    Public Shared ReadOnly Property [Default]() As MyCustomStyleProperties Get Return defaultObject End Get End Property

    '/

    '/ Force static ctor being called at least once. '/ Public Shared Sub Initialize() End Sub 'Initialize

    '/

    '/ Initializes a MyCustomStyleProperties object with a style object that holds all data. '/ Public Sub New(ByVal style As GridStyleInfo) MyBase.New(style) End Sub 'New

    '/

    '/ Initializes a MyCustomStyleProperties object with an empty style object. Design- '/ time environment will use this ctor and later copy the values to a style object '/ by calling style.CustomProperties.Add(otherCustomStyleProperties1). '/ Public Sub New() End Sub 'New

    '/

    '/ Gets / sets TheLocked state. '/

    'Description("Specifies if ..."), Browsable(True), Category("StyleCategoryBehavior")> _ Public Property TheLocked() As Boolean Get TraceUtil.TraceCurrentMethodInfo() Return CBool(style.GetValue(LockedProperty)) End Get Set(ByVal Value As Boolean) TraceUtil.TraceCurrentMethodInfo(Value) style.SetValue(LockedProperty, Value) End Set End Property

    '/

    '/ Resets TheLocked state. '/ Public Sub ResetTheLocked() style.ResetValue(LockedProperty) End Sub 'ResetTheLocked

    'EditorBrowsableAttribute(EditorBrowsableState.Never)> _ Private Function ShouldSerializeTheLocked() As Boolean Return style.HasValue(LockedProperty) End Function 'ShouldSerializeTheLocked '/

    '/ Gets if TheLocked state has been initialized for the current object. '/

    'Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _ Public ReadOnly Property HasTheLocked() As Boolean Get Return style.HasValue(LockedProperty) End Get End Property

    '/

    '/ Gets / sets TheFont state. TheFont is itself an expandable object '/ with several properties that can be set individually and participate '/ in style inheritance mechanism. '/

    'Description("The font for drawing text."), Browsable(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Category("StyleCategoryAppearance")> _ Public Property TheFont() As GridFontInfo Get Return CType(style.GetValue(TheFontProperty), GridFontInfo) End Get Set(ByVal Value As GridFontInfo) style.SetValue(TheFontProperty, Value) End Set End Property

    '/

    '/ Resets TheFont state. '/ Public Sub ResetTheFont() style.ResetValue(TheFontProperty) End Sub 'ResetTheFont

    'EditorBrowsableAttribute(EditorBrowsableState.Never)> _ Private Function ShouldSerializeTheFont() As Boolean Return style.HasValue(TheFontProperty) End Function 'ShouldSerializeTheFont '/

    '/ Determines if TheFont state has been initialized for the current object. '/

    'Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _ Public ReadOnly Property HasTheFont() As Boolean Get Return style.HasValue(TheFontProperty) End Get End Property End Class 'MyCustomStyleProperties

    Constructors

    GridStyleInfoCustomProperties()

    Initializes the new instance ofGridStyleInfoCustomPropertiesCollection class with an empty GridStyleInfo object. When you later set the StyleInfo property, the changes in this object will be copied over to the new GridStyleInfo object.

    Declaration
    protected GridStyleInfoCustomProperties()
    Remarks

    The CustomProperties collection adds design-time support for custom properties by adding empty custom property objects and later calling Add(GridStyleInfoCustomProperties), which will result in changing the StyleInfo property for this object and forces copying all properties of this object to the style object.

    GridStyleInfoCustomProperties(GridStyleInfo)

    Initializes the new instance ofGridStyleInfoCustomPropertiesCollection class with a GridStyleInfo that the properties of this class will belong to.

    Declaration
    protected GridStyleInfoCustomProperties(GridStyleInfo style)
    Parameters
    Type Name Description
    GridStyleInfo style

    The GridStyleInfo that holds and gets the data for this custom property object.

    Fields

    style

    The GridStyleInfo that holds and gets the data for this custom property object.

    Declaration
    protected GridStyleInfo style
    Field Value
    Type
    GridStyleInfo

    Properties

    StyleInfo

    Gets or sets the GridStyleInfo that holds and gets the data for this custom property object. When you set the StyleInfo property, all prior changes in this object will be copied over to the new GridStyleInfo object.

    Declaration
    public GridStyleInfo StyleInfo { get; set; }
    Property Value
    Type
    GridStyleInfo

    Methods

    CreateStyleInfoProperty(Type, String)

    Registers a new custom property.

    Declaration
    protected static StyleInfoProperty CreateStyleInfoProperty(Type componentType, string propertyName)
    Parameters
    Type Name Description
    System.Type componentType

    The type of your derived custom property class.

    System.String propertyName

    The name of the property. This must match a property member in your class.

    Returns
    Type Description
    StyleInfoProperty

    A StyleInfoProperty object that you should use for getting and setting values.

    CreateStyleInfoProperty(Type, String, StyleInfoPropertyOptions)

    Registers a new custom property.

    Declaration
    protected static StyleInfoProperty CreateStyleInfoProperty(Type componentType, string propertyName, StyleInfoPropertyOptions propertyOptions)
    Parameters
    Type Name Description
    System.Type componentType

    The type of your derived custom property class.

    System.String propertyName

    The name of the property. This must match a property member in your class.

    StyleInfoPropertyOptions propertyOptions

    Specifies attributes for the property.

    Returns
    Type Description
    StyleInfoProperty

    A StyleInfoProperty object that you should use for getting and setting values.

    CreateStyleInfoProperty(Type, Type, String)

    Registers a new custom property.

    Declaration
    protected static StyleInfoProperty CreateStyleInfoProperty(Type componentType, Type type, string propertyName)
    Parameters
    Type Name Description
    System.Type componentType

    The type of your derived custom property class.

    System.Type type

    The type of the property.

    System.String propertyName

    The name of the property. This must match a property member in your class.

    Returns
    Type Description
    StyleInfoProperty

    A StyleInfoProperty object that you should use for getting and setting values.

    CreateStyleInfoProperty(Type, Type, String, StyleInfoPropertyOptions)

    Registers a new custom property.

    Declaration
    protected static StyleInfoProperty CreateStyleInfoProperty(Type componentType, Type type, string propertyName, StyleInfoPropertyOptions propertyOptions)
    Parameters
    Type Name Description
    System.Type componentType

    The type of your derived custom property class.

    System.Type type

    The type of the property.

    System.String propertyName

    The name of the property. This must match a property member in your class.

    StyleInfoPropertyOptions propertyOptions

    Specifies attributes for the property.

    Returns
    Type Description
    StyleInfoProperty

    A StyleInfoProperty object that you should use for getting and setting values.

    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved