By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

pixel width of a character of a font

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
steven wrote:
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....
Nov 21 '05 #2

P: n/a
beaker wrote:
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
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.