Erro ao Chavar um User Control no Visual Studio

26/04/2012

Pessoal.

Fiz um User Control para testes que cria uma nova propriedade para um Textbox no qual este colocará a primeira letra de cada palavra em maiusculo.

O User Control é criado normalmente mas quando vou criar um projeto e colocar este User Control no Visual Studio aparece a tela com o erro: Code genaration for Property CharacterCasing failed. Error was: The value -1 is not a valid value for the enum ExtendedCharacterCasing.

Como resolvo isso?

O meu código é:

Designer:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class TextBoxEx
Inherits System.Windows.Forms.TextBox


Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

NOTE: The following procedure is required by the Windows Form Designer
It can be modified using the Windows Form Designer.
Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
End Sub

Classe:

Imports System.ComponentModel

Public Class TextBoxEx : Inherits TextBox
Public Sub New()
MyBase.New()

This call is required by the designer.
InitializeComponent()

Add any initialization after the InitializeComponent() call.

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Private _casingSelected As ExtendedCharacterCasing
Public Enum ExtendedCharacterCasing
Normal
Upper
Lower
Proper
End Enum

<DefaultValue(ExtendedCharacterCasing.Upper)> _
Public Shadows Property CharacterCasing() As ExtendedCharacterCasing
Get
Return _casingSelected
Return MyBase.CharacterCasing = _casingSelected
End Get
Set(ByVal Value As ExtendedCharacterCasing)
_casingSelected = Value

If _casingSelected = ExtendedCharacterCasing.Lower Or _casingSelected = ExtendedCharacterCasing.Normal Or _casingSelected = ExtendedCharacterCasing.Upper Then
MyBase.CharacterCasing = _casingSelected
Else
MyBase.CharacterCasing = Windows.Forms.CharacterCasing.Normal
MyBase.Text = StrConv(MyBase.Text, VbStrConv.ProperCase)
MyBase.Update()

End If


End Set
End Property

Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
If _casingSelected = ExtendedCharacterCasing.Proper Then
Me.Text = StrConv(Me.Text, VbStrConv.ProperCase)
Me.Update()
End If
End Sub

Public Overrides Property Text() As String
Get
If _casingSelected = ExtendedCharacterCasing.Proper Then
Return StrConv(MyBase.Text, VbStrConv.ProperCase)
Return MyBase.Text = StrConv(MyBase.Text, VbStrConv.ProperCase)
Else
Return MyBase.Text
End If
End Get
Set(ByVal Value As String)
MyBase.Text = Value

End Set
End Property
End Class

Hans

Respostas

26/04/2012

Joel Rodrigues Currículo

No constructor do componente, tente definir um valor padrão para essa nova propriedade.
Responder Citar

26/04/2012

Hans

E como poderia ser isso?
Responder Citar

26/04/2012

Joel Rodrigues Currículo

Tente
_casingSelected = Normal

ou algo do tipo, adaptando.
Responder Citar