gpt4 book ai didi

c# - 如何在属性对话框中添加自定义控件属性

转载 作者:太空宇宙 更新时间:2023-11-03 13:55:47 27 4
gpt4 key购买 nike

我想将属性添加到我的自定义控件中,就像上面带有描述的示例属性一样!我不知道像上面那样用 GUI 来显示它。我想知道使用什么属性。


private bool IsNum = true;
[PropertyTab("IsNumaric")]
[Browsable(true)]
[Description("TextBox only valid for numbers only"), Category("EmSoft")]
public bool IsNumaricTextBox
{
set
{
IsNum = value;
}
}

protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
if (IsNum)
{
doStruf(e);
}
}

private void doStruf(KeyPressEventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+") && !char.IsControl(e.KeyChar))
e.Handled = true;
}

我想将其显示为带有描述的属性工具框

在属性框中像这样

IsNumaric 为真

最佳答案

该属性需要一个 Getter 才能显示在属性网格中:

private bool isNum = true;

[PropertyTab("IsNumaric")]
[Browsable(true)]
[Description("TextBox only valid for numbers only"), Category("EmSoft")]
public bool IsNumaricTextBox {
get { return isNum; }
set { isNum = value; }
}

关于c# - 如何在属性对话框中添加自定义控件属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12234464/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com