473,320 Members | 1,839 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.

DrawString error?

I would like to paint a box using DrawString, standard Unicode
characters (box drawings characters) and monospaced font.

Unfortunately for some fonts painted lines contain a break.

Example code, in whom one can see the error:

private void Form1_Paint (object sender, PaintEventArgs e)
(
Font font = new Font ( "Courier New", 9);
e.Graphics.DrawString (new String ( '\u2500', 200),
font,
new SolidBrush (Color.Red), new PointF (0, 0),
StringFormat.GenericTypographic);
)

I must use DrawString, not the DrawLine etc. fuctions.
Does anybody knows how paint lines via the DrawString, so that did not
have the breaks?
Sep 19 '08 #1
9 2952
TAB
Hi

If I understand you right, you mean a line break or word wrap, if so you
could use
StringFormat strFormat = StringFormat.GenericTypographic;
strFormat.FormatFlags |= StringFormatFlags.NoWrap;
"kynos" <ni**************@gazeta.plskrev i meddelandet
news:3d**********************************@m3g2000h sc.googlegroups.com...
I would like to paint a box using DrawString, standard Unicode
characters (box drawings characters) and monospaced font.

Unfortunately for some fonts painted lines contain a break.

Example code, in whom one can see the error:

private void Form1_Paint (object sender, PaintEventArgs e)
(
Font font = new Font ( "Courier New", 9);
e.Graphics.DrawString (new String ( '\u2500', 200),
font,
new SolidBrush (Color.Red), new PointF (0, 0),
StringFormat.GenericTypographic);
)

I must use DrawString, not the DrawLine etc. fuctions.
Does anybody knows how paint lines via the DrawString, so that did not
have the breaks?
Sep 19 '08 #2
Hi,

Thanks for your reply, but I do not mean word wrap or a line break.
If you choose Courier New, _eight_ pts font, and DrawString using
string containts some graphical unicode character ('horizontal line')
you have straight line without gaps on it.

But if you choose _nine_ pts (and several another sizes) font there
are gaps on the line.

Please, try the code I posted before - it looks really strange.
Sep 19 '08 #3
TAB
Using your example, I get a straight red line across the form, no gaps.
Something wrong with your font file?

"kynos" <ni**************@gazeta.plskrev i meddelandet
news:12**********************************@f36g2000 hsa.googlegroups.com...
Hi,

Thanks for your reply, but I do not mean word wrap or a line break.
If you choose Courier New, _eight_ pts font, and DrawString using
string containts some graphical unicode character ('horizontal line')
you have straight line without gaps on it.

But if you choose _nine_ pts (and several another sizes) font there
are gaps on the line.

Please, try the code I posted before - it looks really strange.
Sep 19 '08 #4
I have got gaps on XP Pro SP3 and Vista Ultimate SP1.
The example was run on MSV C# Express Edition 2008.

Have you tried my code with 8 pts and 9 pts font size?
And there is no difference betwen them?
On my systems, with the 9 pts font, the gaps size is about 1 pixel,
and take place every few (5) character.
Sep 19 '08 #5
TAB
I have so far tried 7, 7.5, 8, 8.5 9, 10, 11 and they all show nothing like
you describe, so I am still aiming at a font problem or maybe a graphics
driver problem?

"kynos" <ni**************@gazeta.plskrev i meddelandet
news:55**********************************@x35g2000 hsb.googlegroups.com...
I have got gaps on XP Pro SP3 and Vista Ultimate SP1.
The example was run on MSV C# Express Edition 2008.

Have you tried my code with 8 pts and 9 pts font size?
And there is no difference betwen them?
On my systems, with the 9 pts font, the gaps size is about 1 pixel,
and take place every few (5) character.
Sep 19 '08 #6
Did you use Courier New font?
Sep 19 '08 #7
On Fri, 19 Sep 2008 05:38:40 -0700, kynos <ni**************@gazeta.pl>
wrote:
[...]
I must use DrawString, not the DrawLine etc. fuctions.
Does anybody knows how paint lines via the DrawString, so that did not
have the breaks?
The bottom line: you _cannot_ depend on being able to draw text characters
and have them produce some specific graphical output, such as a line.
Judicious choices for font family and size can produce nearly-perfect
results, and you might have some better success using the TextRenderer
class, but there will always be exceptions.

If you want a 100% reliable line, you must use DrawLine().

If you can explain why it is you want to restrict yourself to using
DrawString(), it's possible someone could suggest an alternative direction
to take that still meets whatever goal you have. Surely the goal is not
in and of itself to only use DrawString().

Pete
Sep 19 '08 #8
TAB
Yes, exact copy of your example. Only changed font size. By the way, I'm
running Vista SP1, .NET 3.5 VS 2008 C# Express.

"kynos" <ni**************@gazeta.plskrev i meddelandet
news:99**********************************@f63g2000 hsf.googlegroups.com...
Did you use Courier New font?
Sep 19 '08 #9
TextRenderer seems to be better way - I will have to test it.
Tank you Tab & Peter.
Sep 19 '08 #10

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

Similar topics

1
by: timtos | last post by:
I am working on a custom treeView and have some problems with a) node.Bounds.Width b) concatenate strings drawn with DrawString(...) a) I want to highlight a selected node and used the...
1
by: David Lindgren | last post by:
Hello! I am using the DrawString method with different StringAlignments passed to it and the result varies alot! Take a look at this screenshot:...
1
by: Drew | last post by:
I posted this to framework.drawing, but did not get any responses... Maybe here?? I am drawing some text using DrawString() and using a bounding rectangle so that when the string is too long it...
1
by: Joao | last post by:
Hi, I'm trully excited to use VB.NET's PrintDocument to make my printouts. On them I draw strings, images and lines. All perfect, if I invoke the Print or the PrintPreview one time per run. At...
5
by: johnb41 | last post by:
I need to print out a string of text and obviously i'm using the DrawString command. But the string must be placed AFTER some "programmatically generated text" (also printed using DrawString). ...
2
by: ChrisNightingale | last post by:
Hi everybody, I have an odd issue which I'm not sure how to resolve. I'm basically implementing a print mechanism which takes a series of controls and reproduces them on a print document. So...
5
by: simon28317 | last post by:
I'm just learning how to program in java. I wrote my first java program, but got an error. Here is my program. import java.awt.*; import java.applet.*; public class me extends Applet { ...
2
by: Tony Johansson | last post by:
Hello! If I use the DrawString below with object of StringFormat as the last object it works good. If I instead remove object StringFormat below as the last object of DrawString I get some rows...
6
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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
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.