pixel width of a character of a font

S

steven

Hello,

I'm having some difficulties with labels. Suppose I have 2 labels, with
a random text in the default font (Microsoft Sans Serif). I want to
place them next to each other, with minimal space between them. So I
want to set the size of the first label so that the text exactly fits in
the label. With this size, I can afterwards set the location of the
second label so that my goal is achieved (place these labels exactly
next to each other).

How can I set the size of a label so that it exactly fits the text ?

l = new label
l.text = "Some random text"
l.location = new point(10, 10)
l.size = new size (X, Y) <= THESE X and Y have to be calculated
me.controls.add(l)

thank you

Steven
 
B

beaker

steven said:
Hello,

I'm having some difficulties with labels. Suppose I have 2 labels, with
a random text in the default font (Microsoft Sans Serif). I want to
place them next to each other, with minimal space between them. So I
want to set the size of the first label so that the text exactly fits in
the label. With this size, I can afterwards set the location of the
second label so that my goal is achieved (place these labels exactly
next to each other).

How can I set the size of a label so that it exactly fits the text ?

l = new label
l.text = "Some random text"
l.location = new point(10, 10)
l.size = new size (X, Y) <= THESE X and Y have to be calculated
me.controls.add(l)

thank you

Steven

You could set l.AutoSize = True to get it to resize to its content, then
measure its size afterwards and use this info to position the second
label....
 
S

steven

beaker said:
You could set l.AutoSize = True to get it to resize to its content, then
measure its size afterwards and use this info to position the second
label....

That works perfect! Thank you very much.

Steven
 

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