Solved

set Justify in text box !

Posted on 2004-08-03
4
659 Views
Last Modified: 2008-02-01
How can i set justify in a textbox (VB6) , not left or right, just only justify (look like in MS Word) ?

UtVoi.
0
Comment
Question by:utvoi
4 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 11703434
set multiline to true, if not use Richtextbox
0
 
LVL 18

Expert Comment

by:JR2003
ID: 11704173
no can do in a textbox
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 399 total points
ID: 11708427
If you use a RichTextBox as EDDYKY has suggested, then you can use the following code to set full justification.  It comes from waty at this topic: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20909676.html

Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_USER = &H400
Private Const EM_SETTYPOGRAPHYOPTIONS = WM_USER + 202
Private Const TO_ADVANCEDTYPOGRAPHY = 1
Private Const EM_SETPARAFORMAT = WM_USER + 71
Private Const PFA_LEFT = 1
Private Const PFA_RIGHT = 2
Private Const PFA_CENTER = 3
Private Const PFA_JUSTIFY = &H4
Private Const MAX_TAB_STOPS = 32

Private Type PARAFORMAT2
    cbSize                     As Long
    dwMask                     As Long
    wNumbering                 As Integer
    wEffects                   As Integer
    dxStartIndent              As Long
    dxRightIndent              As Long
    dxOffset                   As Long
    wAlignment                 As Integer
    cTabCount                  As Integer
    rgxTabs(MAX_TAB_STOPS - 1) As Long
    dySpaceBefore              As Long
    dySpaceAfter               As Long
    dyLineSpacing              As Long
    sStyle                     As Integer
    bLineSpacingRule           As Byte
    bOutlineLevel              As Byte
    wShadingWeight             As Integer
    wShadingStyle              As Integer
    wNumberingStart            As Integer
    wNumberingStyle            As Integer
    wNumberingTab              As Integer
    wBorderSpace               As Integer
    wBorderWidth               As Integer
    wBorders                   As Integer
End Type

Public Enum ERECParagraphAlignmentConstants
   ercParaLeft = PFA_LEFT
   ercParaCentre = PFA_CENTER
   ercParaRight = PFA_RIGHT
   ercParaJustify = PFA_JUSTIFY
End Enum
Private Const PFM_ALIGNMENT = &H8&

Private Sub Form_Load()
    RichTextBox1.Text = ""
    SetAlignment RichTextBox1.HWND, ercParaJustify
End Sub

Private Function SetAlignment(lHwnd As Long, ByVal eAlign As ERECParagraphAlignmentConstants)
    Dim tP2 As PARAFORMAT2
    Dim lR As Long
    tP2.dwMask = PFM_ALIGNMENT
    tP2.cbSize = Len(tP2)
    tP2.wAlignment = eAlign
    lR = SendMessageLong(lHwnd, EM_SETTYPOGRAPHYOPTIONS, TO_ADVANCEDTYPOGRAPHY, TO_ADVANCEDTYPOGRAPHY)
    lR = SendMessage(lHwnd, EM_SETPARAFORMAT, 0, tP2)
End Function
0
 

Author Comment

by:utvoi
ID: 11712643
Yeah ! that is wat i expect ! thx all  for ur help, especially Idle_Mind !
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

23 Experts available now in Live!

Get 1:1 Help Now