Odd Character

awdigrigoli

Member
Joined
Mar 30, 2005
Messages
12
Programming Experience
5-10
Hello,

A strange character is returned when Alt+NumPad1 is clicked in my VB.NET Windows Application.
Has anyone else come across this? If so could you help me understand why and/or how to stop it from happening?

Thank you,
Anthony
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
those are the font's ascii symbols, you can use the Character Map to view them for all the fonts you have Start > Programs > Accessories > System Tools > Character Map

and to disallow them in your apps just write a quick keypress routine so it wont allow any characters that you dont want like:

VB.NET:
Friend Const gstrValidChars As String = "abcdefghijklmnopqrstuvwxyz'- ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	Friend Sub KeyPress(ByRef Sender As Object, ByRef e As System.Windows.Forms.KeyPressEventArgs, ByVal AllowAllChars As Boolean)
		Dim TextBox As TextBox = CType(Sender, TextBox)
		Dim strLastChar As String
		'Handles all the name fields in the app
		If Asc(e.KeyChar) <> Keys.Back Then
			If AllowAllChars = False And InStr(gstrValidChars, e.KeyChar) = 0 Then
			    'If an invalid char is passed then its dropped
				e.Handled = True
			Else
			    If e.KeyChar.IsLetter(e.KeyChar) = True Then
				    TextBox.SelectedText = ""
				    If TextBox.TextLength <> 0 Then
					    strLastChar = Mid(TextBox.Text, TextBox.TextLength, 1)
					Else
					    strLastChar = "'"
					End If
				    If strLastChar = " " Or strLastChar = "-" Or strLastChar = "'" Then
					    TextBox.SelectedText = e.KeyChar.ToUpper(e.KeyChar)
					    e.Handled = True
					End If
				End If
			End If
		End If
	End Sub

to use this simply call it in the keypress event of the textbox you want it used in:
VB.NET:
Private Sub txtCustName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCustName.KeyPress
	Call KeyPressName(sender, e, False)
End Sub
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
glad to know it's working for ya (i've been using that sub that i wrote for almost a year now lol )
 
Top