473,320 Members | 2,164 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.

is it possible to change fonts in a graphics drawstirng?

hey, I want to draw one thing, then dynamically change fonts to a different
font in the same string. can I do that?? any help ?? it needs to be using
"Graphics.Drawstring" method

myactual problem is that I want to put certain, small writing underneath
certain strings in a print preview

but since the larger text is a different font, the amount of carriage
returns is different then the smaller font. which in turn causes inconsistent
spaces between the items.

if I could however, keep the text the same font, do a bunch of carriage
returns, THEN change to the smaller font, I could make the amount of carriage
returns equal all across the page.

confused yet?

thanks.
Aug 24 '07 #1
4 2666
Rogelio wrote:
hey, I want to draw one thing, then dynamically change fonts to a different
font in the same string. can I do that??
Yes. Just call DrawString a second time with the same parameters
(including the string), except with a different Font.
[...]
but since the larger text is a different font, the amount of carriage
returns is different then the smaller font. which in turn causes inconsistent
spaces between the items.

if I could however, keep the text the same font, do a bunch of carriage
returns, THEN change to the smaller font, I could make the amount of carriage
returns equal all across the page.
Are you using a single call to DrawString to render all of the text for
a given page? If so, then you are going to have trouble doing what you
want. You could draw two different strings, one in each font, in the
same rectangle, but getting the second string's text to get positioned
exactly where you want it is likely to be a huge headache.

A better approach would be to handle the line-breaks yourself, drawing
one line at a time. Then you have control over where each line is
drawn, and you can go back and draw smaller text relative to the line
without losing track of where the next full-size line should go.

Pete
Aug 24 '07 #2
Hi,

"Rogelio" <Ro*****@discussions.microsoft.comwrote in message
news:37**********************************@microsof t.com...
hey, I want to draw one thing, then dynamically change fonts to a
different
font in the same string. can I do that?? any help ?? it needs to be using
"Graphics.Drawstring" method
Yep, that will do, just call it twice. You might have to be careful about
positioning and font size though.
myactual problem is that I want to put certain, small writing underneath
certain strings in a print preview

but since the larger text is a different font, the amount of carriage
returns is different then the smaller font. which in turn causes
inconsistent
spaces between the items.
You have to position your text as you need. Take a look at MeasureString.
Aug 24 '07 #3
I think I have an idea. I will use DrawRectangle. by using Draw Rectangle, I
can set EXACT coordinates.

once the rectangles are drawn, I can use Drawstring to draw a string inside
the rectangles.

I can set the height of the rectangles to the height of the text using
GetHeight to a font object.

any advice?
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

"Rogelio" <Ro*****@discussions.microsoft.comwrote in message
news:37**********************************@microsof t.com...
hey, I want to draw one thing, then dynamically change fonts to a
different
font in the same string. can I do that?? any help ?? it needs to be using
"Graphics.Drawstring" method

Yep, that will do, just call it twice. You might have to be careful about
positioning and font size though.
myactual problem is that I want to put certain, small writing underneath
certain strings in a print preview

but since the larger text is a different font, the amount of carriage
returns is different then the smaller font. which in turn causes
inconsistent
spaces between the items.

You have to position your text as you need. Take a look at MeasureString.
Aug 24 '07 #4
Rogelio wrote:
I think I have an idea. I will use DrawRectangle. by using Draw Rectangle, I
can set EXACT coordinates.
You can set exact coordinates just drawing the string too.
once the rectangles are drawn, I can use Drawstring to draw a string inside
the rectangles.
You can draw a string inside a rectangle whether or not you actually
draw the rectangle.
I can set the height of the rectangles to the height of the text using
GetHeight to a font object.
It would be better to just use MeasureString() as Ignacio suggested to
find out what rectangle the string occupies. Then you can use the
dimensions of that rectangle to determine the height of the text, where
to draw the smaller text, etc.

Pete
Aug 24 '07 #5

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

Similar topics

8
by: Randell D. | last post by:
I have just recompiled, upgraded to PHP 4.3.4. As an exercise (and curiosity) I've decided to test out PDF functions and got the test in the PHP online manual working. I had one problem whereby...
2
by: anna | last post by:
Firefox Mozilla Browser Fonts / Format / rich text / webmail question I have Comcast. They do not support Firefox so they won't help me. When I use Mozilla firefox browser to access my web...
2
by: Nathan Guill | last post by:
Everytime I change a font (from the properties window) I get an error. I can remove the line of code VB generates and I get no errors, but I would like to be able to change fonts. Any ideas what...
2
by: jm | last post by:
There are properties for OwnerDraw on ContextMenu items. I know it can be done with regular menus. I cannot find anyone doing it with the systray icon contextmenu (notifyicon.) Is it possible to...
0
by: Rob Richardson | last post by:
Greetings! How would I write code that will send a line of text with two or more fonts to a printer? The MSDN help document for the PrintDocument() class gives me enough information to change...
1
by: rockdc1981 | last post by:
is there any way to do this or were stocked with the standard
1
by: =?Utf-8?B?YXNj?= | last post by:
recently upgraded to MSxp professional 03 and now I can't change the fonts or the color in outlook. Also, everytime I want to start a new e-mail I get the following message. "One or more ActiveX...
1
by: krikaran adel | last post by:
Hi, First of all I found your tips very usfull, of course these tips becuas of all years working in access. really greet site. my Quation: is this away to change fonts in reports so the...
2
by: desertavataraz | last post by:
I am going write an application in C++ that allows the user to see two languages at once, and allows them to search each individual language for words or keywords. I have a font that I made...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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
isladogs
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...
1
isladogs
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...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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

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.