Solved

TextBox Alignment

Posted on 2000-03-20
22
618 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
  • 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now