Página 1 de 1

Making TLables in code ... strange Font and Width behaviour

Publicado: Jue Dic 31, 2015 11:32 am
por ChrisGillard
Happy New Year to everyone, but still doing a bit of work in 2015.

A simple test program with a mainform and making 3 TLabels in code. All 3 TLabels have same width and height. Xailer 4.0

All works OK as expected without any lBold
2015-12-31_10-08-52.png
2015-12-31_10-08-52.png (49.35 KiB) Visto 6412 veces
When I make TLabel3, :lBold := TRUE ...

- All 3 TLabels go bold?

- TLabel1 & TLabel2 chop of some text on the right hand side, nWidth has changed?
2015-12-31_10-10-49.png
2015-12-31_10-10-49.png (59.68 KiB) Visto 6412 veces
Here is my simple code ....

METHOD FormInitialize( oSender ) CLASS TForm1

local oLabel1, oLabel2, oLabel3

oLabel1 := TLabel():New( self )
oLabel1:SetBounds( 200, 150, 300, 30 )
oLabel1:cText := "In Code, TLabel 300 wide"
oLabel1:Create()

oLabel2 := TLabel():New( self )
oLabel2:SetBounds( 200, 200, 300, 30 )
oLabel2:cText := "In Code Red, TLabel 300 wide"
oLabel2:nClrText := CLR_RED
oLabel2:Create()


oLabel3 := TLabel():New( self )
oLabel3:SetBounds( 200, 250, 300, 30 )
oLabel3:cText := "In Code Red and this one BOLD, TLabel 300 wide"

// Without this line .... all TLabels are OK
// When I include this line .... all TLabels go BOLD!!
oLabel3:oFont:lBold := TRUE

// Adding these lines to give oLabel3 its own oFont .... does not solve the problem.
// oLabel3:lParentFont := .F.
// oLabel3:oFont := TFont():Create( "MS Sans Serif", 8, 0, 400 )

oLabel3:nClrText := CLR_RED
oLabel3:Create()

RETURN Nil

So question is what am I doing wrong or what is going on here?

Thank you for any thoughts.

Chris

Re: Making TLables in code ... strange Font and Width behaviour

Publicado: Jue Dic 31, 2015 1:43 pm
por ChrisGillard
Hmmm .... images in my post seem to be the wrong way round and I don't seem to be able to edit the sequence of the images and save it.

Non Bold OK image should be the first one in the post.

lBold = TRUE with All TLabels in Bold? and strange width effects should be in the second position.

Sorry to make this confusing!

Chris

Re: Making TLables in code ... strange Font and Width behaviour

Publicado: Vie Ene 01, 2016 8:52 pm
por ignacio
Hello,

Change the property lParentFont to FALSE and lAutoSize to FALSE on TLabel controls.

Regards,

Re: Making TLables in code ... strange Font and Width behaviour

Publicado: Lun Ene 04, 2016 10:57 am
por ChrisGillard
Hi Ignacio,

Thanks for the reply.

The two properties, lParentFont to FALSE and lAutoSize to FALSE, have solved my length problems

I still have a problem with the line

TLable3:oFont:lBold

This is setting all my labels to bold

Should I be making a new oFont for oLabel3 ?

Hopefully nearly there.

Chris

Re: Making TLables in code ... strange Font and Width behaviour

Publicado: Mié Ene 13, 2016 10:12 am
por jfgimenez
Chris,

fonts are shared (by default) among all controls in the form. So, when you write ::oLabel3:oFont:lBold := .F., you are changing that font attribute for all controls.

The way to change it for only one control is by creating a new font for it: ::oLabel3:oFont := TFont():Create( "MS Sans Serif", 9,, 700 )

Re: Making TLables in code ... strange Font and Width behaviour

Publicado: Jue Ene 28, 2016 5:21 pm
por ChrisGillard
Jose,

Thanks for the confirmation that fonts are shared by all controls on the form and how to get round it.

Slightly different subject ..... is the any way of making a Label with a basic text colour but highlighting one or two characters in another characters ?

I suspect not easy, maybe the possibility of using two controls one in basic colour and an cleverly positioned second control in the highlight colour ?

Any other thoughts, please.

Thanks

Chris

Re: Making TLables in code ... strange Font and Width behaviour

Publicado: Jue Ene 28, 2016 5:52 pm
por ignacio
Take a look at TLabelEx and this sample:

\xailer\samples\LabelEx.

Regards,
2016-01-28 17_49_41-Source.png
2016-01-28 17_49_41-Source.png (19.69 KiB) Visto 6010 veces

Re: Making TLables in code ... strange Font and Width behaviour

Publicado: Mar Feb 02, 2016 3:47 pm
por ChrisGillard
Hi Ignacio,

TLabelEx looks very promising for what I have in mind ... thank you.

My last wish is for the same text flebility in Tbutton objects .... that would make my life complete, at the moment!!

I dont know what else you have planned for Xailer over the coming months and years but maybe a UI with more HTML possibilities?

Would be nice but I have absolutely no idea how it could be done!!

Thanks again.

Chris