I read in a text file;
trim the lines;
establish the lengths of the lines.
Measured lengths bear no relationship to actual lengths;
the listBox uses a true type.
What is the cause of this?
How can this be overcome?
Thank you,
Patrick. 7 3049
Hi Patrick,
I assume you are referring to Graphics.Measur eString(). It is a fast,
simple, but unreliable method to quickly calculate the length of a
string. MeasureString will report a size slightly larger than the actual
space taken by the string.
The method adds extra space to "optimize display quality", so if you put
several strings after eachother you will find some space between the
strings. If you need exact measurements you need to use
Graphics.Measur eCharacterRange s() which is a whole lot more complex, and
more sensitive to resolution.
Happy coding!
Morten Wennevik [C# MVP]
Hi Morten,
Actually I was just doing len = blabla.Length;
Patrick
"Morten Wennevik" <Mo************ @hotmail.com> wrote in message
news:opr7gv8jhn hntkfz@localhos t...
Hi Patrick,
I assume you are referring to Graphics.Measur eString(). It is a fast,
simple, but unreliable method to quickly calculate the length of a
string. MeasureString will report a size slightly larger than the actual
space taken by the string.
The method adds extra space to "optimize display quality", so if you put
several strings after eachother you will find some space between the
strings. If you need exact measurements you need to use
Graphics.Measur eCharacterRange s() which is a whole lot more complex, and
more sensitive to resolution.
Happy coding!
Morten Wennevik [C# MVP]
Patrick de Ridder <wa********@all .here> wrote: Actually I was just doing len = blabla.Length;
That gives the length of the string in characters.
Was that what you were after? If so, could you give an example of how
the observed length was different to the actual length?
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
In that case, the Length property of a string reports the number of
characters, not how long the string appears on the screen (which is
dependent on font and screen resolution).
String.Trim() will remove blank characters like space, tab, carriage
return, new line at the beginning and the end of the string (note you need
to use newstring = oldstring.Trim( )) because the original string will
never be changed.
For a truetype font,
string text1 = "iiiiiiiiii ";
// text1.Length = 10, but width is 29.5 units with default font
string text2 = "mmmmmmmmm" ;
// text2.Length = 9, but width is 88.5 units with default font
but text1 will appear shorter on screen because the truetype has variable
widths for different characters and i is very thin.
If you want the strings to be the same equivalent width as length you need
to use a fixed size font, like Courier New.
Happy coding!
Morten Wennevik [C# MVP]
Hi,
Thanks, yes, String.Len counts characters.
How do find out which fonts are true type besides courier new?
Patrick.
To find out if the current font is truetype, or monotype, you need to
measure the size of two characters that would be different sized in
truetype, like 'i' and 'm'
string i = "iii";
string m = "mmm";
Graphics g = MyControl.Creat eGraphics();
if(g.MeasureStr ing(i, MyControl.Font) != g.MeasureString (m,
MyControl.Font) )
// truetype
else
// monotype
g.Dispose();
Happy coding!
Morten Wennevik [C# MVP]
Hi Morten,
I ended up trying them *all* out, saw them, and ... did
without a straight edge in the end, not all that cool anyway.
Thank you for your responses.
Patrick.
"Morten Wennevik" <Mo************ @hotmail.com> wrote in message
news:opr7iicpqr hntkfz@localhos t...
To find out if the current font is truetype, or monotype, you need to
measure the size of two characters that would be different sized in
truetype, like 'i' and 'm'
string i = "iii";
string m = "mmm";
Graphics g = MyControl.Creat eGraphics();
if(g.MeasureStr ing(i, MyControl.Font) != g.MeasureString (m,
MyControl.Font) )
// truetype
else
// monotype
g.Dispose();
Happy coding!
Morten Wennevik [C# MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: G Kannan |
last post by:
Hey all!
I have written a perl script to retrieve information from a HTML Form
and insert the data into an Oracle database table. I am gettting the
the following error message:
"Use of uninitialized value in concatenation (.) at register.pl line
38, <STDIN> line 10."
The PERL code is as follows:
|
by: Hal Vaughan |
last post by:
Is there a maximum length for Javascript program lines?
What about strings? Is there a limit on string length?
I found some references that said the maximum string length was 256
characters, but I have a program that created a string of over 25,000
characters (the browser was Konqueror).
Are there limits on these lengths? If I require a newer browser for the
program I'm writing, would that change the situation?
|
by: DLP22192 |
last post by:
I have the following single-line if statement that is evaluating true even
though it shouldn't. I have never seen this before and I am concerned that
this can happen in other areas of my code.
If String1.Length > 0 Then String2 = String1
where String1 = ""
This statement also evaluates as true when String1 = "":
|
by: jamait |
last post by:
Hi all,
I m trying to read in a text file into a datatable...
Not sure on how to split up the information though, regex or substrings...?
sample:
Col1 Col2 Col3
Col4
A0012430 REKAL TVÄTTMEDEL EKOMAX 0,5L ST 75.9000
|
by: Koen |
last post by:
Hi all,
I created a little database to manage my e-books.
The program will synchronize a table with the contents of a directory.
Works great.
Because I keep additional info (like keywords) to the created
records in the database and I don't want to lose all that info
when I rename a file and synchronise, I've added some code to
the program. It works like this: when the filename of a DB records
| |
by: Adi |
last post by:
Hello eveyone,
I wanna ask a very simple question here (as it was quite disturbing
me for a long time.)
My problem is to read a file line by line. I've tried following
implementations but still facing problems:
Assume that
FILE* filePointer;
unsigned char lineBuffer;
|
by: WStoreyII |
last post by:
the following code is supposed to read a whole line upto a new line
char from a file. however it does not work. it is producing weird
results. please help. I had error checking in there for mallocs and
ect, but i removed them to help me debug. thanks.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void freadl ( FILE *stream, char **string ) {
|
by: LEM |
last post by:
Hi,
I'm trying to remove any empty lines from a string, and I am doing the
following:
String pp;
pp = "\r\n\r\n1\r\n23\r\n\r\n4";
pp = pp.Replace("\r\n\r\n", "\r\n");
|
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= |
last post by:
This is an example of the data;
2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511)
RX 74 bytes
2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13
48
2007/07/27 11:00:03 52 00 52 02 02 C7 83 D7 07 07 1B 0B 00 00 00
00
2007/07/27 11:00:03 28 0A 06 06 06 06 06 06 06 06 06 06 06 0A 06
06
|
by: Spiros Bousbouras |
last post by:
I'm thinking of adding a command to vim for removing
white space from the end of each line of a C source
file. Can anyone think of a situation where such white
space might be useful ?
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |