Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
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-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated