本文介绍了如何创建用户控件的customer属性,使用户能够在设计时分配字符串类型变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
推荐答案
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:
我的问题是,在设计模式下,在安全级别的属性窗格中,而不是int值(0/1),我想分配int类型的公共变量说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();
}
}
[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();
}
}
}
这取自 RoundedButton 控件,参见示例这里: []
This is taken from RoundedButton control, see example here: RoundedButton Control - Demystifying DrawArc[^]
这篇关于如何创建用户控件的customer属性,使用户能够在设计时分配字符串类型变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!