Home All Groups Group Topic Archive Search About

ShouldSerialize problem in inherited control

Author
16 Jan 2006 1:27 AM
James Wong
Dear all,

I'm using VB.NET 2003 and designing a custom control which inherits from
TextBox.  In this inherited control, I would like to reassign default value
of some
properties, such as BorderStyle.  I found that it is impossible to change
default value using ShouldSerialize and Reset pair in design form which
consume my custom control.

My custom control is in attachement.  I have changed the default value of
BorderStyle to FixedSingle in custom control.  However, in design form, the
default value is still Fixed3D if I click Reset on BorderStyle in property
panel.  How can I solve this problem?

Thanks for your attention and kindly help!

Regards,
James Wong

[attached file: ctrTestBox.vb]

Author
16 Jan 2006 4:09 AM
Rocky
Don't use ShouldSerialize and Reset. See example below:

Option Explicit On
Option Strict On
Imports System.ComponentModel

Public Class MyNewText
    Inherits System.Windows.Forms.TextBox

    Public Sub New()
        MyBase.New()
        MyBase.BorderStyle = BorderStyle.FixedSingle
    End Sub

    <DefaultValue(GetType(BorderStyle), "FixedSingle")> _
        Public Shadows Property BorderStyle() As BorderStyle
        Get
            Return MyBase.BorderStyle
        End Get
        Set(ByVal Value As BorderStyle)
            MyBase.BorderStyle = Value
        End Set
    End Property

End Class







Show quoteHide quote
"James Wong" <cphk_msdn@nospam.nospam> wrote in message
news:uUoNPvjGGHA.2708@TK2MSFTNGP11.phx.gbl...
> Dear all,
>
> I'm using VB.NET 2003 and designing a custom control which inherits from
> TextBox.  In this inherited control, I would like to reassign default
> value of some
> properties, such as BorderStyle.  I found that it is impossible to change
> default value using ShouldSerialize and Reset pair in design form which
> consume my custom control.
>
> My custom control is in attachement.  I have changed the default value of
> BorderStyle to FixedSingle in custom control.  However, in design form,
> the
> default value is still Fixed3D if I click Reset on BorderStyle in property
> panel.  How can I solve this problem?
>
> Thanks for your attention and kindly help!
>
> Regards,
> James Wong
>
>
>
Author
16 Jan 2006 11:41 AM
James Wong
Hi Rocky,

It works!  Thanks a lot!

James

Show quoteHide quote
"Rocky" <nopl***@nowhere.com> ¼¶¼g©ó¶l¥ó·s»D:uOUfXKlGGHA.1***@TK2MSFTNGP09.phx.gbl...
> Don't use ShouldSerialize and Reset. See example below:
>
> Option Explicit On
> Option Strict On
> Imports System.ComponentModel
>
> Public Class MyNewText
>    Inherits System.Windows.Forms.TextBox
>
>    Public Sub New()
>        MyBase.New()
>        MyBase.BorderStyle = BorderStyle.FixedSingle
>    End Sub
>
>    <DefaultValue(GetType(BorderStyle), "FixedSingle")> _
>        Public Shadows Property BorderStyle() As BorderStyle
>        Get
>            Return MyBase.BorderStyle
>        End Get
>        Set(ByVal Value As BorderStyle)
>            MyBase.BorderStyle = Value
>        End Set
>    End Property
>
> End Class
>
>
>
>
>
>
>
> "James Wong" <cphk_msdn@nospam.nospam> wrote in message
> news:uUoNPvjGGHA.2708@TK2MSFTNGP11.phx.gbl...
>> Dear all,
>>
>> I'm using VB.NET 2003 and designing a custom control which inherits from
>> TextBox.  In this inherited control, I would like to reassign default
>> value of some
>> properties, such as BorderStyle.  I found that it is impossible to change
>> default value using ShouldSerialize and Reset pair in design form which
>> consume my custom control.
>>
>> My custom control is in attachement.  I have changed the default value of
>> BorderStyle to FixedSingle in custom control.  However, in design form,
>> the
>> default value is still Fixed3D if I click Reset on BorderStyle in
>> property panel.  How can I solve this problem?
>>
>> Thanks for your attention and kindly help!
>>
>> Regards,
>> James Wong
>>
>>
>>
>
>