vb.netwinformscontrolscreateparams

Unable to set property value VB.NET


I'm making a custom form for my library

Public Class MycustomForm : Inherits Form

    Private Const CP_NOCLOSE_BUTTON As Integer = &H200
    Private _CloseBox As Boolean = True

    Public Sub New()
        MyBase.New()
    End Sub
    <Category("WindowStyle")> _
    <DefaultValue(True)> _
    <Description("This property enables or disables the close button")> _
    Public Property CloseBox As Boolean
        Get
            Return _CloseBox
        End Get
        Set(value As Boolean)
            If value <> _CloseBox Then
                value = _CloseBox
                Me.RecreateHandle()
            End If
        End Set
    End Property

    Protected Overrides ReadOnly Property CreateParams As CreateParams
        Get
            Dim CustomParams As CreateParams = MyBase.CreateParams
            If Not _CloseBox Then
                CustomParams.ClassStyle = CustomParams.ClassStyle Or CP_NOCLOSE_BUTTON
            End If
            Return CustomParams
        End Get
    End Property

End Class

I created a property to offer developers the possibility of disable the close button

When I test my form in the designer, I changed the MyForm.Designer:

Partial Class MyForm
    Inherits MycustomForm

After, the property has been added, when I try to change the property to False, I'm unable to change it, because the property not changes

What am I doing wrong?


Solution

  • You have made a simple mistake.

    Change value = _CloseBox to _CloseBox = value