Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleRight justify a single line TextBox
Keywordstext, alignment, right justify
CategoriesStrings, Controls, API
 
Create a multi-line TextBox that is only tall enough to display 1 line and set its Alignment property to 1 - Right Justify. Then discard all carriage return characters. Use subclassing to disable the TextBox's context menu so the user cannot cut and paste a carriage return into the TextBox.

My book Custom Controls Library uses subclassing to create a similar control.

*** Warning ***

Subclassing is dangerous. The debugger does not work well when a new WindowProc is installed. If you halt the program instead of unloading its forms, it will crash and so will the Visual Basic IDE. Save your work often! Don't say you weren't warned.

 
' Discard CrLf and Ctrl-V.
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As _
    Integer)
Const Ctrl_V = 22

    If KeyAscii = Asc(vbLf) Then KeyAscii = 0
    If KeyAscii = Ctrl_V Then KeyAscii = 0
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated