Solved

TextBox Alignment

Posted on 2000-03-20
22
626 Views
Last Modified: 2008-02-01
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
Comment
Question by:Maximka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
  • 2
  • +2
22 Comments
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2639583
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
 
LVL 12

Expert Comment

by:pjknibbs
ID: 2639588
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
 
LVL 1

Author Comment

by:Maximka
ID: 2640000
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 54

Expert Comment

by:nico5038
ID: 2642306
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
 
LVL 1

Author Comment

by:Maximka
ID: 2643582
OK, and what will I do when user will try to input his string into the TextBox ?

Cheers.
0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2644249
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
 
LVL 1

Author Comment

by:Maximka
ID: 2644270
Thank You , I know it and I did it ,but it doesn't help.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 2645568
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
 
LVL 1

Author Comment

by:Maximka
ID: 2649993
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2650033
is this justifying just a single line or multiline?
0
 
LVL 1

Author Comment

by:Maximka
ID: 2650043
Single, but MultiLine = True
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2650090
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2659706
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
 
LVL 28

Accepted Solution

by:
AzraSound earned 50 total points
ID: 2667768
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
 
LVL 1

Author Comment

by:Maximka
ID: 2668180
Sorry , but there is no TextBox in Forms2 in my VB5.
Thanks.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2668205
really?  hmmm...i could send you the dll...see if it works
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2668221
i thought it was old...the textbox contol looks like a label control in the components box
0
 
LVL 1

Author Comment

by:Maximka
ID: 2668228
Thanks.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2668246
thanks for what?  you find the textbox?
0
 
LVL 1

Author Comment

by:Maximka
ID: 2668267
You right TextBox looks like Label , but
it haven't Alignment property at all.
Thanks.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2668273
its not called alignment.  the property is textalign

Textbox1.textalign = fmtextalignright
0
 
LVL 1

Author Comment

by:Maximka
ID: 2668276
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question