Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Space at the top of text



Permlink Replies: 3 - Last Post: Aug 30, 2017 10:59 AM Last Post By: Roy Lambert
Roy Lambert

Posts: 1,063
Registered: 8/7/01
Space at the top of text
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 29, 2017 4:41 AM
Sorry for the title but I don't know the correct term.

I want to line up two labels so that it looks as though they have the same top. These two labels can have widely different font sizes (eg 24 vs 12).

My first (and so far only) attempt is

ReminderContact.Top := ReminderTime.Top+ +( (ReminderTime.Height - ReminderTime.Canvas.TextHeight(ReminderTime.Caption)) div 2);

Unfortunately there is a gap between the top of the text and the top of the label so whilst the labels have the same top position the actual text looks offset.

Is it possible to achieve this?

Roy Lambert

Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Space at the top of text
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 29, 2017 5:32 AM   in response to: Roy Lambert in response to: Roy Lambert
Found the font.height property and have tried

gap1 := (label1.Height + label1.Font.Height);
gap2 := (label2.Height + label2.Font.Height);
gap3 := (label3.Height + label3.Font.Height);
label2.Top := label1.Top + gap1 + gap2;
label4.Top := label3.Top + gap3 + gap2;

Lable1 has style set to bold, label4 as normal and there is a difference of (eyeball count) 2 or 3 pixels so its getting better


Roy Lambert

Mitch Wolberg

Posts: 18
Registered: 6/9/97
Re: Space at the top of text
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 30, 2017 10:44 AM   in response to: Roy Lambert in response to: Roy Lambert
Take a look at GetTextMetrics, it has all he information you need.

On 8/29/2017 6:32 AM, Roy Lambert wrote:
Found the font.height property and have tried

gap1 := (label1.Height + label1.Font.Height);
gap2 := (label2.Height + label2.Font.Height);
gap3 := (label3.Height + label3.Font.Height);
label2.Top := label1.Top + gap1 + gap2;
label4.Top := label3.Top + gap3 + gap2;

Lable1 has style set to bold, label4 as normal and there is a difference of (eyeball count) 2 or 3 pixels so its getting better


Roy Lambert

Roy Lambert

Posts: 1,063
Registered: 8/7/01
Re: Space at the top of text
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 30, 2017 10:59 AM   in response to: Mitch Wolberg in response to: Mitch Wolberg
Mitch

Looks good - yet another bit I knew nothing about - I'll investigate

Roy Lambert

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02