align a label in center hor and vertical

W

Wilfried Mestdagh

Hi,

I want to add a Label on a panel programatically. No problem. But I
can't seems to manage that the label is centered horizontal and vertical
in the panel. I experimented with TextAlign and Dock but no real
success. I probably forget something. Some hints really welcome :)
 
?

=?iso-8859-1?q?Horacio_Nu=F1ez_Hern=E1ndez?=

Hi,

I want to add a Label on a panel programatically. No problem. But I
can't seems to manage that the label is centered horizontal and vertical
in the panel. I experimented with TextAlign and Dock but no real
success. I probably forget something. Some hints really welcome :)

Hi,
You mean align text or align position?

you could use:

Label lbl //...

lbl.position.x = panel.width/2 - lbl.width/2; //horizontal
lbl.position.y = panel.height/2 - lbl.height/2; //vertical


___
http://elblogdehoracio.blogspot.com
 
B

Bruce Wood

Hi,

I want to add a Label on a panel programatically. No problem. But I
can't seems to manage that the label is centered horizontal and vertical
in the panel. I experimented with TextAlign and Dock but no real
success. I probably forget something. Some hints really welcome :)

The only way I know of to centre things is to handle the resizing
events on the parent container and readjust the label's position
accordingly... "manually" as it were.

In other words, do a take on Horacio's solution, but you have to do it
whenever the parent container changes size.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top