• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 644
  • Last Modified:

TextBox Alignment

How can I set RightJustify alignment for TextBox at runtime in VB5 (ReadOnly property ). I used the :

lRet = SendMessage(Handle, 1089 , -32767, 0)
and it worked in Win95/98 , but in win 2000 it doesn't.
Any ideas ?

Thanks .
0
Maximka
Asked:
Maximka
  • 9
  • 8
  • 2
  • +2
1 Solution
 
pjknibbsCommented:
Dunno about VB5, but the Alignment property of a TextBox is definitely *not* read-only in VB6--have you actually tried setting the alignment directly?
0
 
pjknibbsCommented:
N.B. The documentation states it's read-only, but I've written a little program which assigns a value at run time and it works!
0
 
MaximkaAuthor Commented:
No I'm sure that it is read only property ,
I think that there are 2 versions of VB on You machine 5 and 6 , so in this case the VB6 vbmvb60.dll is above vbmvb50.dll and this is the reason , but if You will try to compile your code on machine without VB6( and never wasn't ) then You will see that You can't set Alignment of textbox to RightJustify.

Thanks.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
nico5038Commented:
Just an uggly workaround:
Calculate the length of the text string,
take the length of the text box and add for the difference a number of space characters in front of the text.

0
 
MaximkaAuthor Commented:
OK, and what will I do when user will try to input his string into the TextBox ?

Cheers.
0
 
paulstampCommented:
Just a though Maximka - if I remember rightly in VB5 the alignment property of a text box only works (even at design time) if the multiline property of the textbox is set to true.
0
 
MaximkaAuthor Commented:
Thank You , I know it and I did it ,but it doesn't help.
0
 
nico5038Commented:
Another work aroud:
Create under Win95/98 an ocx with textbox with right justify and a property to set it then use the compiled version under 2000.
0
 
MaximkaAuthor Commented:
I tried and it didn't work , I think that it doesn't matter that it is OCX , because I used the same SendMessage .

Thanks.
0
 
AzraSoundCommented:
is this justifying just a single line or multiline?
0
 
MaximkaAuthor Commented:
Single, but MultiLine = True
0
 
AzraSoundCommented:
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. 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. Now for the code. This is an example using three text boxes in an array named Text1().

In the module:
Public OldWindowProc As Long

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const GWL_WNDPROC = (-4)
Public Const WM_CONTEXTMENU = &H7B
' *********************************************
' Pass along all messages except the one that
' makes the context menu appear.
' *********************************************
Public Function NewWindowProc(ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If msg <> WM_CONTEXTMENU Then _
        NewWindowProc = CallWindowProc( _
            OldWindowProc, hWnd, msg, wParam, _
            lParam)
End Function


Private Sub Form_Load()
Dim i As Integer

    For i = 0 To 2
        OldWindowProc = SetWindowLong( _
            Text1(i).hWnd, GWL_WNDPROC, _
            AddressOf NewWindowProc)
    Next i
End Sub


Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = 22 Then KeyAscii = 0
    If KeyAscii = 13 Then KeyAscii = 0
End Sub

0
 
AzraSoundCommented:
It doesnt appear that this is possible with VB5 apparently.  You may consider creating an invisible right justified textbox with the exact same dimensions as your left justified one and upon whatever event that fires the need to change to a right justified textbox, just switch the two boxes' visibility values.  It would be easy to interchange the current text between the two as well.  
0
 
AzraSoundCommented:
maximka,
if you go to project|components and choose the Forms 2.0 Object Library, the textbox in there supports alignment adjustment as runtime
0
 
MaximkaAuthor Commented:
Sorry , but there is no TextBox in Forms2 in my VB5.
Thanks.
0
 
AzraSoundCommented:
really?  hmmm...i could send you the dll...see if it works
0
 
AzraSoundCommented:
i thought it was old...the textbox contol looks like a label control in the components box
0
 
MaximkaAuthor Commented:
Thanks.
0
 
AzraSoundCommented:
thanks for what?  you find the textbox?
0
 
MaximkaAuthor Commented:
You right TextBox looks like Label , but
it haven't Alignment property at all.
Thanks.
0
 
AzraSoundCommented:
its not called alignment.  the property is textalign

Textbox1.textalign = fmtextalignright
0
 
MaximkaAuthor Commented:
O , AzraSound I'm sorry You absolutly right it has property called TextAlign and it realy supports resetting Alignment in runtime I accept Your answer.
Thank You very much man.
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 8
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now