Pregunta: | 35821 - JUSTIFICAR TEXTO EN UN PICTURE BOX |
Autor: | Xavi |
Como puedo justificar un campo de texto (memo) en un picture box?
Gracias |
Respuesta: | Xavi |
Navegando por la red, he encontrado este codigo:
Función para imprimir texto justificado en un PictureBox. Sub justifica_picture(p As PictureBox, x0, xf, y0, txt) ' Muestra un texto justificado dentro del picture "p" ' x0, xf = posicion de los margenes izquierdo y derecho ' y0 = posicion vertical donde se desea empezar a escribir ' txt = texto a escribir Dim x, y, k, ancho Dim s As String, ss As String Dim x_spc s = txt x = x0 y = y0 ancho = (xf - x0) While s <> "" ss = "" While (s <> "") And (p.TextWidth(ss) <= ancho) ss = ss & Left$(s, 1) s = Right$(s, Len(s) - 1) Wend If (p.TextWidth(ss) > ancho) Then s = Right$(ss, 1) & s ss = Left$(ss, Len(ss) - 1) End If ' aqui tenemos en ss lo maximo que cabe en una linea If Right$(ss, 1) = " " Then ss = Left$(ss, Len(ss) - 1) Else If (InStr(ss, " ") > 0) And (Left$(s & " ", 1) <> " ") Then While Right$(ss, 1) <> " " s = Right$(ss, 1) & s ss = Left$(ss, Len(ss) - 1) Wend ss = Left$(ss, Len(ss) - 1) End If End If x_spc = 0 x = x0 If (Len(ss) > 1) And (s & "" <> "") Then x_spc = (ancho - p.TextWidth(ss)) / (Len(ss) - 1) End If p.CurrentX = x p.CurrentY = y If x_spc = 0 Then p.Print ss; Else For k = 1 To Len(ss) p.CurrentX = x p.Print Mid$(ss, k, 1); x = x + p.TextWidth("*" & Mid$(ss, k, 1) & "*") - p.TextWidth("**") x = x + x_spc Next End If y = y + p.TextHeight(ss) While Left$(s, 1) = " " s = Right$(s, Len(s) - 1) Wend Wend End Sub Daniel Castillo Martinez, [email protected] |