Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to create the customer property of user control that will enable the user to assign string type variable in design time


What I have tried:

How to create the customer property of user control that will enable the user to assign string type variable in design time
Posted
Updated 9-Feb-18 22:27pm

Just add a property to the control:
public partial class MyUserControl : UserControl
    {
    public string MyProperty { get; set; }
    public MyUserControl()
        {
        InitializeComponent();
        }
    }
Once you compile it, it will add to the toolbox.
Drop that on your form, and the property will appear in the Property Pane as normal.

Quote:
My question is, in design mode, in property pane of "security level" , instead of int value (0/1), i want to assign "int" type public variable say "user_level"

If that's what you need, then ask for that when you ask a question! :laugh:

It's simple: use an Enum.
public partial class MyUserControl : UserControl
    {
    public string MyProperty { get; set; }
    public enum SecurityLevels
        {
        User = 0,
        Admin = 1,
        }
    public SecurityLevels SecurityLevel { get; set; }
    public MyUserControl()
        {
        InitializeComponent();
        }
    }
 
Share this answer
 
v2
Comments
Member 12301682 10-Feb-18 7:26am    
Hi,
I already have configured the "int" type custom property as "Security Level" in my user control. When 0 the control will be enabled and when 1 control will be disabled. This is working fine.
My question is, in design mode, in property pane of "security level" , instead of int value (0/1), i want to assign "int" type public variable say "user_level"

Thanks
In addition to answer 1, you can also add attributes, example:
[Category("Appearance"), Description("Sets/Gets rotated text"), DefaultValue(typeof(string), ""), Bindable(true)]
public string RotatedText
{
    get
    {
        return (rotatedtextstring);
    }

    set
    {
        if (rotatedtextstring != value)
        {
            rotatedtextstring = value;
            this.Refresh();
        }
    }
}

This is taken from RoundedButton control, see example here: RoundedButton Control - Demystifying DrawArc[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900