Hello
I was wondering if its possible to the "width" and "height" of a text when
creating a pic from text.
string sometext = "bla bla";
Font font = new Font("Verdana", 18);
SolidBrush sb = new SolidBrush(Color.Red);
Bitmap tb = new Bitmap(200,60);
Graphics bmpGraphics = Graphics.FromImage(tb);
bmpGraphics.Clear(Color.White);
bmpGraphics.DrawString(sometext, font, sb, 14, 10);
in this case i create a 200x60, but I would like to create one that is as
wide and high as the text.
is that possible? even when changing font?
TIA
/Lasse 3 10983
DOH! :D
font.GetHeight
"Lasse Edsvik" <la***@nospam.com> wrote in message
news:uY****************@TK2MSFTNGP12.phx.gbl... Hello
I was wondering if its possible to the "width" and "height" of a text when creating a pic from text.
string sometext = "bla bla"; Font font = new Font("Verdana", 18);
SolidBrush sb = new SolidBrush(Color.Red);
Bitmap tb = new Bitmap(200,60);
Graphics bmpGraphics = Graphics.FromImage(tb);
bmpGraphics.Clear(Color.White);
bmpGraphics.DrawString(sometext, font, sb, 14, 10); in this case i create a 200x60, but I would like to create one that is as wide and high as the text.
is that possible? even when changing font?
TIA /Lasse
Lasse Edsvik wrote: Hello
I was wondering if its possible to the "width" and "height" of a text when creating a pic from text.
string sometext = "bla bla"; Font font = new Font("Verdana", 18);
SolidBrush sb = new SolidBrush(Color.Red);
Bitmap tb = new Bitmap(200,60);
Graphics bmpGraphics = Graphics.FromImage(tb);
bmpGraphics.Clear(Color.White);
bmpGraphics.DrawString(sometext, font, sb, 14, 10); in this case i create a 200x60, but I would like to create one that is as wide and high as the text.
is that possible? even when changing font?
TIA /Lasse
There is a MeasureString method that returns an approximate (!) size.
Hans Kesting
Hi Lasse,
As Hans said you can use Graphics.MeasureString which calculates the size of a string based on a certain font.
It is not 100% accurate but I believe it will return at least the size and then a tiny bit more.
If you want accurate size you need to use Graphics.MeasureCharacterRanges
--
Happy coding!
Morten Wennevik [C# MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John MacIntyre |
last post by:
Hi,
Using the script below, when you click on the radio button beside click here
.... the first row shrinks.
Has anybody else ever experienced this?
Does anybody know of a logical...
|
by: Georg Goerg |
last post by:
hello,
i want to make website with a top navigation bar and one on the left.
so by using css i define three layers and everyone of them has length attr.
in percents.
but if i want to put...
|
by: Gérard Talbot |
last post by:
Hello all,
I'd like to know and understand the difference between, say,
<img src="/ImageFilename.png" width="123" height="456" alt="">
and
<img src="/ImageFilename.png" style="width:...
|
by: Thomas Wang |
last post by:
I draw a combobox on a form, but I can not change its height,
What I can do about it?
B.Rgds
|
by: Dag Sunde |
last post by:
I have the following function to resize a div element (Content) depending on
the
size of another div element (leftConent).
function adjustContentHeight() {
var content =...
|
by: fredo |
last post by:
This question was asked in comp.lang.javascript with no result.
In IE5.x and IE6, I want to display an image when the user rolls over a
text link. The image does indeed display, but only on the...
|
by: Tantale |
last post by:
I used this serviec to check my webpage
http://www.jmrw.com/Abroad/Barcelone/index.htm Made with Dreamweaver 8.
The result is 206 errors, most of them "end tag omitted, but OMITTAG NO was...
|
by: Phil Endecott |
last post by:
Dear Experts,
It looks as if the HTML4 spec does not define a meaning for empty height
and width attributes in an IMG element. Moz seems to ignore them, while
IE7 sets the dimension to 1 pixel...
|
by: Christian Hackl |
last post by:
Hi everyone,
I've got a question about what makes the "img" element's width/height
attributes valid HTML or XHTML.
First of all, this is a rather theoretical question, but digging through
the...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |