Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 883259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:33:30+00:00 2026-05-15T12:33:30+00:00

How can I write my own structs which can be used as a property

  • 0

How can I write my own structs which can be used as a property during design time? I need to be able to specify a default value, and have a selectable list of pre-defined structs for the designer to pick from, in much the same way as Color properties are implemented.

Furthermore, how can I do this with classes, like Font does? How can you specify sub-properties in the property window?


I’m writing a custom control which has a lot of different visual-type elements, such as gradient colors, widths, percentages, etc. I want these to all be customizable, but also to be able to be set all at once with different Styles. I can do this at run-time by making a Style struct property and having it change all the other properties in the setter. What I would like is for users at design time to be able to select pre-defined Styles such as “Light Blue,” “Dark Grey,” etc., each of which would set all the other UI properties (the gradients, etc.) If I could have all the UI properties appear under the “Style” property, much like “Bold” and “Italic” appear under “Font,” that would be ideal.


Code:

[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] 
public partial class GradientPanel : UserControl
{
    public PanelStyle Style
    {
        get
        {
            return new PanelStyle()
            {
                BackgroundFade = this.BackgroundFade,
                EdgeColor = this.EdgeColor,
                BorderColor = this.BorderColor,
                EdgeWidth = this.EdgeWidth,
                LowerColor = this.LowerColor,
                UpperColor = this.UpperColor
            };
        }
        set
        {
            this.SuspendLayout();
            this.BackgroundFade = value.BackgroundFade;
            this.EdgeColor = value.EdgeColor;
            this.BorderColor = value.BorderColor;
            this.EdgeWidth = value.EdgeWidth;
            this.LowerColor = value.LowerColor;
            this.UpperColor = value.UpperColor;
            this.ResumeLayout();
        }
    }

    ....

    public struct PanelStyle
    {
        public float BackgroundFade;
        public Color EdgeColor;
        public int EdgeWidth;
        public Color BorderColor;
        public Color UpperColor;
        public Color LowerColor;

        public static PanelStyle System = new PanelStyle()
        {
            BackgroundFade = .7f,
            EdgeColor = SystemColors.Window,
            BorderColor = SystemColors.WindowFrame,
            EdgeWidth = 6,
            LowerColor = SystemColors.Control,
            UpperColor = SystemColors.Window
        };
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:33:30+00:00Added an answer on May 15, 2026 at 12:33 pm

    Structs are difficult to deal with in a PropertyGrid because they are value types. Assigning a field or a property of a struct has no effect, the entire struct value needs to be assigned.

    Note how Font is a class, setting individual Font properties in the grid is not a problem. Font has a TypeConverter (System.Drawing.FontConverter) which takes a string and converts it to a Font. That’s why you can edit the Font value directly instead of having to expand the node and edit individual properties. It also has a UITypeEditor, System.Drawing.Design.FontEditor, which presents the dialog when you click the button with the dots.

    Which is what you probably need to do for your property if you want to use to pick from predefined styles. A good example of a UITypeEditor for a struct is System.Drawing.Design.ColorEditor, use Reflector to have a look at the class. To just expose the properties you need a TypeConverter, a good example of one for a struct type is System.Drawing.PointConverter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.