473,569 Members | 2,844 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 2643
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
3166
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! http://www.pocellular.com ==================================================
9
19510
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: How do I determine how many characters I can get on a line Question 3: How do I determine how many lines I can get on a page. Assume no margins...
3
2386
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 width. Is there a way to find the size of a char in pixel given the font name and size. I have tried using System.Drawing.Graphics object, but the...
2
10535
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 the width of the cell, I can get the length of the text, but the cell.width is in pixels, while the text length is measured based on points (font...
5
1429
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
1229
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 be able to calculate) the left and rightmost pixels of the text. However, this is a problem because not all letters have their leftmost pixel at...
2
2459
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 will then strip out when it comes to drawing the treenode into the treeview... Anyway I know there is a way to get the pixel length of a string...
12
14469
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, that has limited width but multiple lines. Currently I am using the left$() function to trim the text to a standard number of characters. I want a...
3
1613
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 foo.center(10, " ") + " | "
30
26466
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 Tip came from one of our own resident Experts, mshmyob. In response to a Thread relating to this very Topic, mshmyob came up with a rather ingenious...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7668
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5218
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2111
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 we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.