473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Specific Font Size question

Hi,

I've read most of the discussions about
"calculation of string width in pixels or points" - they mostly talk
about MeasureString (and that it's not exact width) or more presize
but requiring much more code MeasureCharacterRanges -
and no one answered this guy's question (I had the same) -
http://www.dotnet247.com/247referenc...39/198205.aspx

Any way, my task is _not_ to draw anything but for existing fixed-width
font - "MS Sans Serif, 8" - to calculate the width of the string, so I
used this simplistic approach I've found on the Web:

string Label;
.....
Font defFont = new Font("MS Sans Serif", 8);
float TextWidth = defFont.SizeInPoints * Label.Length;

Works Ok, but I saw on screen that if I choose a Bold variant of
the font, then the string width _increases_.

So I did the following, but .NET C# returns me the same value
as with non-Bold case:

Font defFontBold = new Font("MS Sans Serif", 8,
(System.Drawing.FontStyle)1);

float TextBoldWidth = defFontBold.SizeInPoints * Label.Length;

Does anyone know why SizeInPoints is not changing for Bold style?

--
Regards,
Paul
Nov 17 '05 #1
4 6700
MS Sans Serif is not a fixed width font. It's proportional. Making the font
bold will increase the length of the string.

Courier new is a fixed width font.

SizeInPoints returns a measure of the height of the font in points. Changing
the style of the font won't change it's height.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Paul Gorodyansky" <pa*****@compuserve.com> wrote in message
news:42***************@compuserve.com...
Hi,

I've read most of the discussions about
"calculation of string width in pixels or points" - they mostly talk
about MeasureString (and that it's not exact width) or more presize
but requiring much more code MeasureCharacterRanges -
and no one answered this guy's question (I had the same) -
http://www.dotnet247.com/247referenc...39/198205.aspx

Any way, my task is _not_ to draw anything but for existing fixed-width
font - "MS Sans Serif, 8" - to calculate the width of the string, so I
used this simplistic approach I've found on the Web:

string Label;
....
Font defFont = new Font("MS Sans Serif", 8);
float TextWidth = defFont.SizeInPoints * Label.Length;

Works Ok, but I saw on screen that if I choose a Bold variant of
the font, then the string width _increases_.

So I did the following, but .NET C# returns me the same value
as with non-Bold case:

Font defFontBold = new Font("MS Sans Serif", 8,
(System.Drawing.FontStyle)1);

float TextBoldWidth = defFontBold.SizeInPoints * Label.Length;

Does anyone know why SizeInPoints is not changing for Bold style?

--
Regards,
Paul

Nov 17 '05 #2
Thanks!

I was browsing through SO many pages about this issue at once
that probably lost control over my brain :-) - the page about
font.SizeInPoints was probably #65 in the row, so I did not realize
that it was completely wrong - because I do know that 8 is a height
and not a width :-)

Thanks, again,

--
Regards,
Paul
Nov 17 '05 #3
Hi,

How to get System.Windows.Forms.PaintEventArgs -
e.Graphics - without really painting anything?

I saw many examples of what I need with a function where
an argument is e.Graphics but could not find a way how to
_call_ such function, i.e. how to get e.Graphics in first place...

Thanks,
Paul
Nov 17 '05 #4
The code where I need to add string width calculations, look
like this (so I just need to find out how to obtain e.Graphics used
as an argument in the very last line)

==============================
namespace fieldValidater
{
class Class1
[STAThread]
static void Main(string[] args)
{
checkStringsWidth(args[0], args[1]);
}
static void StringsWidth(string formName, string serverName)
{
...
Font defFont = new Font("MS Sans Serif", 8);

<loop to get strings>
<current string processing:>
....
int a2 = MeasureDisplayStringWidth(Graphics g, curString, defFont);
}
}
===============================
--
Regards,
Paul
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

133
by: Philipp Lenssen | last post by:
Why is there no standardized and well-working way for a web-page to offer the font for download/embed it, in order to be displayed on the page? No matter what you think of the preferred font of a...
131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
55
by: Haines Brown | last post by:
I've been setting font-size 1em; as the default in my style sheets. Until now, that seemed to be ok. But now I'm beginning to wonder. My aim is to have an easily readable, but not overly large...
39
by: David Jubinville | last post by:
Hi All, I've run into a bit of an interesting problem with CSS and font DPI and would certainly welcome help. Problem: Page layout defined in CSS has font size issues (overlapping frames,...
9
by: Dr John Stockton | last post by:
Assuming default set-ups and considering all reasonable browsers, whatever that may mean, what should an author expect that his readers in general will see (with visual browsers) for a page with...
9
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:...
1
by: j7.henry | last post by:
I am trying to pull specific data that is in a comma delimited file into a web page. So if my comma delimited file looks like: Name,Address,Zip Fred,123 Elm,66666 Mike,23 Jump,11111 I would...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
2
by: shiloh | last post by:
Hi. I need help. I am using javascript to come up with a loan's amortization schedule. Everything is already in place except for adding up the values of a certain field that is generated by a...
1
by: deepakNagpal | last post by:
hi, this is deepak, i got stuck in a script where i want to apply a platform specific css. i will be greatful if anyone could help me out. My PHP code is: <?php $agent =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.