473,503 Members | 10,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pixel width of a character of a font

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
2 2637
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3164
by: Alex Shi | last post by:
In php, is there a way obtain the width of a charactor of a certain font? Alex -- ================================================== Cell Phone Batteries at 30-50%+ off retail prices!...
9
19491
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2:...
3
2378
by: Sangeeta | last post by:
Hi, I have a datagrid where columns are of some fixed pixel size. If any column text increases the width of column, the plan is to truncate it till its pixel width becomes less than the coloumn...
2
10531
by: Kirk Graves | last post by:
I have an html table that I am filling with data from the database. when I put the text in the table, I only display the number of characters that will fit based on the size of the cell. I know...
5
1428
by: John Smith | last post by:
Here is my HTML table formatting code. <table border="1" width="100%"> <tr width = "100%"> <td width="33%">11asdhagdshaskgashjgahjgadhjgdjshdgasjdgajdgadjhgdgahjdgadhjsgad
3
1225
by: Nathan Sokalski | last post by:
I am using GDI+ to generate buttons in my application. Because I want the left and right edges of the buttons to be a certain number of pixels from the start and end of the text, I need to know (or...
2
2448
by: Benny Raymond | last post by:
Since I have no control over a treeview's scroll bars (i'm drawing icons and text to the right of the treenodes) I've decided to just add some special text to the end of my tree node text which I...
12
14440
by: paii, Ron | last post by:
Sorry about that last one. Does anyone know how to calculate the width a string of text for given Font name and size? I want to buildup a block of text strings to display in a unbound control,...
3
1610
by: spohle | last post by:
hi, i got random strings and wanna attach a " | " at the end. now if i print them i want the | to always be underneath each other. example code: foo = for each in foo: print...
30
26440
ADezii
by: ADezii | last post by:
This week’s Tip of the Week will clearly demonstrate how you can dynamically set the Drop Down List Width of a Combo Box to the length of the longest item in its Row Source. The inspiration for this...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.