Custom Textbox Control

I want to have a custom text control that while editing could :

1. Convert to Proper Case.
2. Convert to Upper Case

How could I do this ?

Thank you.
LVL 1
emi_sastraAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

it_saigeDeveloperCommented:
So first things first, you would want to inherit from TextBox; e.g. -
Partial Class TextBoxEx
	Inherits System.Windows.Forms.TextBox

Open in new window

Then you want to decide how a user chooses Proper Case And/Or Upper Case;  e.g. Using a Property set in the designer -
<Category("Behavior"), Description("Specifies the case-setting when the focus of the control is lost.")>
Public Property [CaseType]() As CaseType = CaseType.Standard

Open in new window

Finally, choose when the aforementioned property setting is applied; e.g. OnLostFocus -
Protected Overrides Sub OnLostFocus(e As EventArgs)
	Select Case [CaseType]
		Case CaseType.Proper
			Text = ConvertToProperCase(Text)
		Case CaseType.Upper
			Text = ConvertToUpperCase(Text)
		Case CaseType.Standard
		Case Else
			Exit Select
	End Select
	MyBase.OnLostFocus(e)
End Sub

Open in new window


Full Implementation w/o Conversion methods -

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

	'Control overrides dispose to clean up the component list.
	<System.Diagnostics.DebuggerNonUserCode()> _
	Protected Overrides Sub Dispose(ByVal disposing As Boolean)
		Try
			If disposing AndAlso components IsNot Nothing Then
				components.Dispose()
			End If
		Finally
			MyBase.Dispose(disposing)
		End Try
	End Sub

	'Required by the Control Designer
	Private components As System.ComponentModel.IContainer

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

End Class

Open in new window

TextBoxEx.vb -
Imports System.ComponentModel

Public Class TextBoxEx

	<Category("Behaviour"), Description("Specifies the case-setting when the focus of the control is lost.")>
	Public Property [CaseType]() As CaseType = CaseType.Standard
	Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
		MyBase.OnPaint(e)

		'Add your custom paint code here
	End Sub

	Protected Overrides Sub OnLostFocus(e As EventArgs)
		Select Case [CaseType]
			Case CaseType.Proper
				Text = ConvertToProperCase(Text)
			Case CaseType.Upper
				Text = ConvertToUpperCase(Text)
			Case CaseType.Standard
			Case Else
				Exit Select
		End Select
		MyBase.OnLostFocus(e)
	End Sub
End Class

Public Enum CaseType As Integer
	Standard = 0
	Proper = 1
	Upper = 2
End Enum

Open in new window

-saige-
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
emi_sastraAuthor Commented:
Hi Saige,

Thank you, let me try it first.
0
emi_sastraAuthor Commented:
Hi Saige,

Sorry for late reply.
Thank you very much for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.