不在“控件”中显示我的控件的自定义属性C#Win Forms中的类 [英] Not Displaying custom property of my control in the "Control" class in C# Win Forms

查看:75
本文介绍了不在“控件”中显示我的控件的自定义属性C#Win Forms中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我通过继承 Textbox 开发了用户控件,其中我只是添加了1个属性isValidate其数据类型为 boolean 。现在我面临的问题是,当我写this.ActiveControl时,我看不到isValidate属性,因为Control类没有isValidate属性。所以,任何想法如何管理这个问题?



提前谢谢

Recently I had developed a user control by inheriting the Textbox in which I have just added 1 property "isValidate" whose data type is boolean. Now the problem I am facing is, when I write "this.ActiveControl" I cannot see the "isValidate" property as the "Control" class does not posess the "isValidate" property. So, any idea how to manage this problem?

Thanks in advance

推荐答案

这很容易。假设您的控件类名称是 MyTextBox 。现在你这样做

That's easy. Let's assume your control class name is MyTextBox. Now you do this
MyTextBox txtBox = this.ActiveControl as MyTextBox;
if (txtBox != null)
{
  //Bingo, the active control is MyTextBox
  //Accessing IsValidate property
  txtBox.IsValidate = false;
}



当然,请确保您的财产是公开的。


Of course, make sure your property is public.


这篇关于不在“控件”中显示我的控件的自定义属性C#Win Forms中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆