Justify text in label
Moderator: Rathinagiri
- danielmaximiliano
- Posts: 2763
- Joined: Fri Apr 09, 2010 4:53 pm
- DBs Used: DBF
- Location: Argentina
- Contact:
Justify text in label
Hola a todos:
el control label tiene propiedades como ser "RIGHTALIGN" y "CENTERALIGN"
hay alguna forma de justificar el texto ? mire dentro de C:\HMG.3.5\SOURCE\c_label.c pero encontre que no...
Hello everyone:
the label control has properties such as "RIGHTALIGN" and "CENTERALIGN"
is there any way to justify the text? I looked inside C: \ HMG.3.5 \ SOURCE \ c_label.c but found that no ...
el control label tiene propiedades como ser "RIGHTALIGN" y "CENTERALIGN"
hay alguna forma de justificar el texto ? mire dentro de C:\HMG.3.5\SOURCE\c_label.c pero encontre que no...
Hello everyone:
the label control has properties such as "RIGHTALIGN" and "CENTERALIGN"
is there any way to justify the text? I looked inside C: \ HMG.3.5 \ SOURCE \ c_label.c but found that no ...
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
- Claudio Ricardo
- Posts: 367
- Joined: Tue Oct 27, 2020 3:38 am
- DBs Used: DBF, MySQL, MariaDB
- Location: Bs. As. - Argentina
Re: Justify text in label
Hola...
Code: Select all
DEFINE LABEL Label_AcercaDe_2
ROW 60
COL 205
WIDTH 210
HEIGHT 20
VALUE "Version 1.0 (04/2019)"
FONTNAME "Arial"
FONTSIZE 11
TOOLTIP ""
FONTBOLD .F.
FONTITALIC .F.
FONTUNDERLINE .F.
FONTSTRIKEOUT .F.
HELPID Nil
VISIBLE .T.
TRANSPARENT .F.
ACTION Nil
AUTOSIZE .F.
BACKCOLOR NIL
FONTCOLOR NIL
CENTERALIGN .T.
END LABEL
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
WhatsApp / Telegram: +54 911-63016162
- danielmaximiliano
- Posts: 2763
- Joined: Fri Apr 09, 2010 4:53 pm
- DBs Used: DBF
- Location: Argentina
- Contact:
Re: Justify text in label
centrar no es justificar
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
- Claudio Ricardo
- Posts: 367
- Joined: Tue Oct 27, 2020 3:38 am
- DBs Used: DBF, MySQL, MariaDB
- Location: Bs. As. - Argentina
Re: Justify text in label
Hola...
Lo sé, pero para lograrlo habría que hacer una función que tomando el width del label y
el tamaño de la fuente, cuente caracteres más espacios, y divida la frase aún en medio
de una palabra, insertando un CRLF cada vez.
Alignment Left es lo más aproximado a eso, sólo que no corta las palabras. Cuando tenga un dia libre intentaré hacer la función, mientras dejo preparado
un programita para probarla o si alguien del foro desea hacerla.
Pdt. Le puse fondo blanco para que se note mejor
Lo sé, pero para lograrlo habría que hacer una función que tomando el width del label y
el tamaño de la fuente, cuente caracteres más espacios, y divida la frase aún en medio
de una palabra, insertando un CRLF cada vez.
Alignment Left es lo más aproximado a eso, sólo que no corta las palabras. Cuando tenga un dia libre intentaré hacer la función, mientras dejo preparado
un programita para probarla o si alguien del foro desea hacerla.
Pdt. Le puse fondo blanco para que se note mejor
- Attachments
-
- Label_Justify.zip
- (1.42 MiB) Downloaded 99 times
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
WhatsApp / Telegram: +54 911-63016162
- danielmaximiliano
- Posts: 2763
- Joined: Fri Apr 09, 2010 4:53 pm
- DBs Used: DBF
- Location: Argentina
- Contact:
Re: Justify text in label
Hola a todos : Encontre algo pero es C# pero muestra que se puede..
Code: Select all
public void Justify(System.Windows.Forms.Label label)
{
string text = label.Text;
string[] lines = text.Split(new[]{"\r\n"}, StringSplitOptions.None).Select(l => l.Trim()).ToArray();
List<string> result = new List<string>();
foreach (string line in lines)
{
result.Add(StretchToWidth(line, label));
}
label.Text = string.Join("\r\n", result);
}
private string StretchToWidth(string text, Label label)
{
if (text.Length < 2)
return text;
// A hair space is the smallest possible non-visible character we can insert
const char hairspace = '\u200A';
// If we measure just the width of the space we might get too much because of added paddings so we have to do it a bit differently
double basewidth = TextRenderer.MeasureText(text, label.Font).Width;
double doublewidth = TextRenderer.MeasureText(text + text, label.Font).Width;
double doublewidthplusspace = TextRenderer.MeasureText(text + hairspace + text, label.Font).Width;
double spacewidth = doublewidthplusspace - doublewidth;
//The space we have to fill up with spaces is whatever is left
double leftoverspace = label.Width - basewidth;
//Calculate the amount of spaces we need to insert
int approximateInserts = Math.Max(0, (int)Math.Floor(leftoverspace / spacewidth));
//Insert spaces
return InsertFillerChar(hairspace, text, approximateInserts);
}
private static string InsertFillerChar(char filler, string text, int inserts)
{
string result = "";
int inserted = 0;
for (int i = 0; i < text.Length; i++)
{
//Add one character of the original text
result += text[i];
//Only add spaces between characters, not at the end
if (i >= text.Length - 1) continue;
//Determine how many characters should have been inserted so far
int shouldbeinserted = (int)(inserts * (i+1) / (text.Length - 1.0));
int insertnow = shouldbeinserted - inserted;
for (int j = 0; j < insertnow; j++)
result += filler;
inserted += insertnow;
}
return result;
}*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
- Claudio Ricardo
- Posts: 367
- Joined: Tue Oct 27, 2020 3:38 am
- DBs Used: DBF, MySQL, MariaDB
- Location: Bs. As. - Argentina
Re: Justify text in label
Muy bueno... habrá que traducirlo a C o tal vez se pueda directamente con funciones similares de Harbour
Yo pensé que necesitabas cómo en el Browse o Grid que se llama Justify pero en realidad es alinear
Lástima que nunca se me dió por aprender C#
Yo pensé que necesitabas cómo en el Browse o Grid que se llama Justify pero en realidad es alinear
Lástima que nunca se me dió por aprender C#
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
WhatsApp / Telegram: +54 911-63016162
Re: Justify text in label
Hola Ricardo,Claudio Ricardo wrote: ↑Sat Mar 27, 2021 3:18 am Hola...
Lo sé, pero para lograrlo habría que hacer una función que tomando el width del label y
el tamaño de la fuente, cuente caracteres más espacios, y divida la frase aún en medio
de una palabra, insertando un CRLF cada vez.
Alignment Left es lo más aproximado a eso, sólo que no corta las palabras.
Screenshot_20210326_235600.png
Cuando tenga un dia libre intentaré hacer la función, mientras dejo preparado
un programita para probarla o si alguien del foro desea hacerla.
Pdt. Le puse fondo blanco para que se note mejor![]()
Please take a look for the updated screen of your sample below:
I've replaced a first LABEL control with the RICHEDIT control and add the command
Also I've used the following function call for this label:SET CONTROL Label_1 OF Main NOTEDGE
Note: the above function is available into the MiniguiEx build._SetFormatJustifyRTF ( "Main" , "Label_1" , .T. )
Last edited by gfilatov on Sat Mar 27, 2021 7:25 pm, edited 1 time in total.
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Re: Justify text in label
Hola Ricardo,Claudio Ricardo wrote: ↑Sat Mar 27, 2021 3:18 am Hola...
Lo sé, pero para lograrlo habría que hacer una función que tomando el width del label y
el tamaño de la fuente, cuente caracteres más espacios, y divida la frase aún en medio
de una palabra, insertando un CRLF cada vez.
Alignment Left es lo más aproximado a eso, sólo que no corta las palabras.
Screenshot_20210326_235600.png
Cuando tenga un dia libre intentaré hacer la función, mientras dejo preparado
un programita para probarla o si alguien del foro desea hacerla.
Pdt. Le puse fondo blanco para que se note mejor![]()
There is the following updated source with using RICHEDIT control as Label_1 for HMG
Code: Select all
#include <hmg.ch>
Function Main
Load Window Main
Main.Center
SET CONTROL Label_1 OF Main NOTEDGE
SetProperty ("Main" , "Label_1" , "Value" , "Este vídeo fue una creación audiovisual que se baso en la recopilación de distintos medios visuales para realización de este vídeo. La Ley de Copyright de los Estados Unidos de América especifica que todo vídeo cuyo propósito sea entretenimiento, reportaje, educación, investigación o comentario no infringe los derechos originales de los contenidos y por lo tanto se considera Uso Justo Fair Use bajo la ley estadounidense.")
Main.Label_1.ParaAlignment := RTF_JUSTIFY
SetProperty ("Main" , "Label_2" , "Value" , "Este vídeo fue una creación audiovisual que se baso en la recopilación de distintos medios visuales para realización de este vídeo. La Ley de Copyright de los Estados Unidos de América especifica que todo vídeo cuyo propósito sea entretenimiento, reportaje, educación, investigación o comentario no infringe los derechos originales de los contenidos y por lo tanto se considera Uso Justo Fair Use bajo la ley estadounidense.")
SetProperty ("Main" , "Label_3" , "Value" , "Este vídeo fue una creación audiovisual que se baso en la recopilación de distintos medios visuales para realización de este vídeo. La Ley de Copyright de los Estados Unidos de América especifica que todo vídeo cuyo propósito sea entretenimiento, reportaje, educación, investigación o comentario no infringe los derechos originales de los contenidos y por lo tanto se considera Uso Justo Fair Use bajo la ley estadounidense.")
Main.Activate
Return Nil
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
- danielmaximiliano
- Posts: 2763
- Joined: Fri Apr 09, 2010 4:53 pm
- DBs Used: DBF
- Location: Argentina
- Contact:
Re: Justify text in label
Gracias Grigory , siempre tiene la solucion
saludo a la distancia
saludo a la distancia
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*
Saludos / Regards
DaNiElMaXiMiLiAnO
Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
- Claudio Ricardo
- Posts: 367
- Joined: Tue Oct 27, 2020 3:38 am
- DBs Used: DBF, MySQL, MariaDB
- Location: Bs. As. - Argentina
Re: Justify text in label
Muchas Gracias Grigory... me será de mucha utilidad...
Yo lo hice con EditBox en lugar de Label (subi al foro un programa "Utiles" que tiene un par de funciones así)
Pero vi que Daniel necesita que funcione diferente, añadiendo espacios entre letras como en el .gif
Estaba probando de crear una función pero me traba el calcular bién los pixels que ocupan los caracteres
Lo subo, tal vez sirva como base para lo que Daniel necesita.
En la variable cCad poner el texto.
Thank you very much Grigory ... it will be very useful to me ...
I did it with EditBox instead of Label (I uploaded a program "Utiles" that has a couple of functions like this)
But I saw that Daniel needs it to work differently, adding spaces between letters like in the .gif
I was trying to create a function but I was unable to calculate the pixels that the characters occupy
I upload it, maybe it will serve as a basis for what Daniel needs.
In the variable cCad put the text.
Yo lo hice con EditBox en lugar de Label (subi al foro un programa "Utiles" que tiene un par de funciones así)
Pero vi que Daniel necesita que funcione diferente, añadiendo espacios entre letras como en el .gif
Estaba probando de crear una función pero me traba el calcular bién los pixels que ocupan los caracteres
Lo subo, tal vez sirva como base para lo que Daniel necesita.
En la variable cCad poner el texto.
Thank you very much Grigory ... it will be very useful to me ...
I did it with EditBox instead of Label (I uploaded a program "Utiles" that has a couple of functions like this)
But I saw that Daniel needs it to work differently, adding spaces between letters like in the .gif
I was trying to create a function but I was unable to calculate the pixels that the characters occupy
I upload it, maybe it will serve as a basis for what Daniel needs.
In the variable cCad put the text.
- Attachments
-
- Label_Justify.zip
- (1.42 MiB) Downloaded 101 times
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
WhatsApp / Telegram: +54 911-63016162