Visual Basic - justificar texto en un richtextbox

Life is soft - evento anual de software empresarial
 
Vista:

justificar texto en un richtextbox

Publicado por pablo (3 intervenciones) el 21/06/2004 02:10:19
estoy creando un editor con un richtextbox pero no puedo justificar el texto osea alinearlo de izquierda y derecha
espero una respueta
muchas gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:justificar texto en un richtextbox

Publicado por paulo cézar r. alves (2 intervenciones) el 04/07/2004 19:14:45
Re: justify

as thinker suggested you can use the alignment property in a rich text box. The following snippet shows how to set each one;
<pre>
Private Sub Command1_Click()
Static x As Integer

With RichTextBox1
.SelAlignment = x
End With
x = x + 1
If x = 3 Then x = 0
End Sub
</pre>

hope that helps

Paulo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:justificar texto en un richtextbox

Publicado por paulo cézar r. alves (2 intervenciones) el 04/07/2004 19:14:48
Re: justify

as thinker suggested you can use the alignment property in a rich text box. The following snippet shows how to set each one;
<pre>
Private Sub Command1_Click()
Static x As Integer

With RichTextBox1
.SelAlignment = x
End With
x = x + 1
If x = 3 Then x = 0
End Sub
</pre>

hope that helps

Paulo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

justificar texto en un RichTextBox

Publicado por Joseba Machado (3 intervenciones) el 24/06/2021 16:17:24
Paso un pequeño prototipo. Encontraréis copias de la parte principal de código por internet, por ejemplo en stackoverflow, indicando que no sirve para el RichTextBox original de Microsoft, pero no es cierto, a mí me funciona bien sin tener que usar controles de terceros.

El código de abajo requiere un formulario con un RichTextBox llamado "RichTextBox1" y dos botones llamados "cmdClipboard" y "cmdJustify". El botón del clipboard es solo para poder comparar fácilmente el contenido de la propiedad TextRTF. El botón cmdJustify es para agregar el token de justificado cuando pegamos un texto que viene por ejemplo de otro RichTextBox que contenga negrita y distintas fuentes, colores y tamaños de letra pero esté sin justificar. Al pulsar ese botón se justifica. Si ya estaba justificado no pasa nada porque previamente quita el token y lo vuelve a poner, no lo duplica.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
Const WM_USER = &H400
Const EM_SETTYPOGRAPHYOPTIONS = WM_USER + 202
Const TO_ADVANCEDTYPOGRAPHY = 1
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
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 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
 
Private Sub cmdClipboard_Click()
    Clipboard.Clear
    Clipboard.SetText RichTextBox1.TextRTF
    MsgBox "Copiado al portapapeles"
End Sub
 
Private Sub cmdJustify_Click()
    RichTextBox1.TextRTF = Replace(Replace(RichTextBox1.TextRTF, "\pard\qj\", "\pard\"), "\pard\", "\pard\qj\")
End Sub
 
Private Sub Form_Load()
    DoEvents
    SetAlignment RichTextBox1.HWND, ercParaJustify
End Sub
 
Private Sub Form_Resize()
    RichTextBox1.Move 100, RichTextBox1.Top, Me.Width - 330, Me.Height - 1100
    cmdClipboard.Move RichTextBox1.Left + RichTextBox1.Width - cmdClipboard.Width, RichTextBox1.Top + RichTextBox1.Height + 100
    cmdJustify.Move cmdClipboard.Left - cmdJustify.Width - 100, cmdClipboard.Top
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar