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 10988
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: 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: 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: 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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |