|
|
Title | Right justify a single line TextBox |
Keywords | text, alignment, right justify |
Categories | Strings, 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
|
|
|
|
|
|