Jump to content
PeterPanettone

How to increase the distance between TCheckBox glyph and caption text?

Recommended Posts

Posted (edited)

In Delphi 10.4, is there a way to increase the narrow space between the TCheckBox glyph and the checkbox caption text?

 

image.png.78117ff9136bbe15c928ddc97a754d90.png

 

The WordWrap property of TCheckBox is set to True.

Edited by PeterPanettone

Share this post


Link to post

Are looking after FMX ?

You can use the Edit custom style, to prepare a customized version

image.thumb.png.874e8e898c5804542f27b02655b85b89.png

 

Or you can use OnApplyStyleLookup, where you can grab the single elements from above,

e.g. by usng FindStyleResource('text') ...

 

When you looking for VCL, probably you have to create you own custom component,
or you simply use ' ' space, to get more distance tho the checkbox.

 

Share this post


Link to post
4 minutes ago, Rollo62 said:

When you looking for VCL, probably you have to create you own custom component,
or you simply use ' ' space, to get more distance tho the checkbox.

That will fail quickly for word wrapped captions. :classic_wacko:

Share this post


Link to post
Posted (edited)
2 hours ago, Sherlock said:

That will fail quickly for word wrapped captions.

Only if the text is dynamic or multilang. So in 99.99% the cases could work.

 

image.png.57df3142dbebdeb816894f94859f9a15.png

 

Caption = '   Unga'#13#10'   Bunga'

WordWrap = True

Edited by Attila Kovacs
  • Like 2

Share this post


Link to post

For VCL, you could set the button to owner-draw and then manually draw your own check box however you want, then you can include more spacing in the drawing.  However, you would have to do this at the Win32 API layer, not at the VCL layer.

Share this post


Link to post
10 hours ago, Lars Fosdal said:

Well, what do you know! I actually didn't know you could wordwrap a checkbox caption!

The WordWrap property was added to TButtonControl (which TCheckBox derives from) in Delphi 7.  All it does is enables the BS_MULTILINE window style on the control, so it is possible to enable this style manually in earlier Delphi versions, too.

Share this post


Link to post
On 7/8/2020 at 5:09 PM, Attila Kovacs said:

Caption = '   Unga'#13#10'   Bunga'

WordWrap = True

Holy Frank, this smells. I already learned not to use whitespaces for distancing back in high school.

And while it might work - can you please check if the above functions correctly if "Width = 30" for example?

Share this post


Link to post
2 minutes ago, Attila Kovacs said:

what is your problem?

Nothing, really. As smart people say "if it works it ain't stupid". It's a perfect quick-and-dirty solution which will achieve what you want in this, very specific project and configuration.

 

Lately I like to think in general solutions, that's all. And that is custom drawing.

Share this post


Link to post
6 minutes ago, Attila Kovacs said:

btw. how did you separate the words back in the high school?

I might not phrased myself correctly - forgive me; English is not my native language. The point is, you know exactly what I meant by "distancing". Let's play adults and not starting to argue on choice of words.

  • Like 1

Share this post


Link to post

All good. It was in my comment that this is only for static text, and if you would argue then you should have asked what if somebody want 2.5 x space distance 😉 

Share this post


Link to post

No insult taken. My attention may have slipped - I did not see the static part and for that I apologize.

For the record, my intention was not to argue: I just had to refactor too many lines of code (written 10-15 years ago) which broke or misbehaved on specific modern systems. The days-weeks wasted there taught me to proudly waste hours when I write fresh code which will still work the same way everywhere in the foreseeable future.

 

Do I still have "hacks" like this in production? Hell yes, I do. Do I hate myself for it when I see it? That's a question for a different topic 🙂

  • Like 2

Share this post


Link to post

There are numerous Unicode white space chars of varying width, so adjusting the distance "by character" is possible.

Share this post


Link to post
12 hours ago, aehimself said:

Do I still have "hacks" like this in production? Hell yes, I do. Do I hate myself for it when I see it? That's a question for a different topic 🙂

Don't mess with youself too much,
if Microsoft shows not any attempt to make these controls practically more usable since the last 20+ years, why should we do ?

 

I must really say that meanwhile I hate to fix all the quirks in OS, IDE, tools, libraries, etc.
Enough to do with my own, selfmade errors :classic_blush:

 

  • Like 3

Share this post


Link to post
12 minutes ago, Rollo62 said:

Don't mess with youself too much,
if Microsoft shows not any attempt to make these controls practically more usable since the last 20+ years, why should we do ?

 

I must really say that meanwhile I hate to fix all the quirks in OS, IDE, tools, libraries, etc.
Enough to do with my own, selfmade errors :classic_blush:

 

And in the end, what is the effort worth? Just to say: "In my product 1+1 is still 2 but it looks better than the others".

Share this post


Link to post
5 hours ago, Lars Fosdal said:

There are numerous Unicode white space chars of varying width, so adjusting the distance "by character" is possible.

In my opinion, just because there's a possibility to do something doesn't mean you should use it 🙂

 

2 hours ago, Rollo62 said:

Don't mess with youself too much,
if Microsoft shows not any attempt to make these controls practically more usable since the last 20+ years, why should we do ?

 

2 hours ago, Sherlock said:

And in the end, what is the effort worth? Just to say: "In my product 1+1 is still 2 but it looks better than the others".

 

I do understand and agree with you on this. But it's not for the others, it's because of my own self.

I just don't want to produce code I don't like or as "time-resistant" as I can think of. Whilst it's a good thing it's a curse as well... I can easily waste hours on a single "Hello World" application this way.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×