自定义类作为“自定义控件"的属性在运行时重置值 [英] Custom Class as Property of Custom Control resets values at Run-time

查看:99
本文介绍了自定义类作为“自定义控件"的属性在运行时重置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人帮助...

我在我的这个项目中使用了VB2008 ...

这是我所做的:

我创建了一个自定义类,将其命名为"CustomClass".我为此类"Num1"和"Num2"创建了一些属性,它们都是整数. toSring()被覆盖.我还为此类实现了类型转换器,某些功能被重写为"CanConvertFrom, CanConvertTo, ConvertFrom, ConvertTo, GetStandardValuesSupported and GetStandardValues".

我创建了一个名为"CustomControl"的自定义控件,将"CustomClass"设置为其属性.

Someone Help...

I used VB2008 in this project of mine...

Here is what I did:

I created a Custom Class named it to "CustomClass". I created some properties for this class "Num1" and "Num2" they are both integers. The toSring() was overridden. I also implemented a Type Converter for this class some function were overridden "CanConvertFrom, CanConvertTo, ConvertFrom, ConvertTo, GetStandardValuesSupported and GetStandardValues".

I created a Custom Control named it to "CustomControl", Set CustomClass as its property.

Public Class CustomControl : Inherits Control
   Private _sample As New CustomClass(1,2)

   Public Property sample() as CustomClass
      ''Get here...
      ''Set here...
   End Property
Enc Class


这就是它的样子. PropertyGrid显示我创建的属性.


This is what it looked like. The PropertyGrid displays the Property I created.

-------------
sample | 1,2 |
-------------
Num1   | 1   |
Num2   | 2   |
-------------


一切正常,但是每次我为每个属性设置不同的值时,这些值都会重置为默认值.


All went fine but every time I set a different value to each property the values reset back to their defaults.

推荐答案

我认为您应该定义DesignerSerializationVisibilityAttribute [
I think you should define the DesignerSerializationVisibilityAttribute[^] for the property.


这篇关于自定义类作为“自定义控件"的属性在运行时重置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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