Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2007

Tip: Looking for answers? Try searching our database.

Bug in Graphics.DrawString ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexander Smirnov - 05 Sep 2007 08:16 GMT
If you draw a string that consists of repeating lower case characters
'i' or 'l' or 'j' then starting from 20th character the space between
characters is more than that before 20th character. I got this with a
font "Microsoft Sans Serif" size 8.25
Jani Jarvinen [MVP] - 05 Sep 2007 15:10 GMT
Hello Alexander,

> If you draw a string that consists of repeating lower case characters
> 'i' or 'l' or 'j' then starting from 20th character the space between
> characters is more than that before 20th character. I got this with a
> font "Microsoft Sans Serif" size 8.25

Although a bug is possible, I wouldn't expect one in this case. To
investigate further, could you send us a complete code example that shows
the error, and also state which Visual Studio/.NET Framework version you are
using, what is your application type, and your operating system?

This way we are better able to verify if its a bug or not.

Thanks!

Signature

Regards,

Mr. Jani Jarvinen
C# MVP
Helsinki, Finland
janij@removethis.dystopia.fi
http://www.saunalahti.fi/janij/

Alexander Smirnov - 05 Sep 2007 16:15 GMT
I use Visual Studio 2005 Standard edition SP1.
NET Framework 2.0
Windows XP Professional SP2

Code example:
// form paint event handler
private void Form1_Paint(object sender, PaintEventArgs e) {

e.Graphics.DrawString("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",this.Font,Brushes.Black,
10,10);
    TextRenderer.DrawText(e.Graphics,
"iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",this.Font,new Point(10,30),
Color.Black);
}
//----------

See the difference between the output of DrawString and DrawText.
Same effect for DrawString() in VS2003 Net 1.1 where TextRenderer
isn't available
Ben Schwehn - 15 Sep 2007 20:05 GMT
> See the difference between the output of DrawString and DrawText.
> Same effect for DrawString() in VS2003 Net 1.1 where TextRenderer

I assume this is, because the stem width of the letter is a fractional
pixel value so DrawString tries to apply some kerning to make up for
this with less then ideal results.

You can actually influence this behaviour by setting
System.Drawing.Text.TextRenderingHint to e.g. SingleBitPerPixel or
AntiAlias like this:

e.Graphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAlias

But in my opinion the result is even worse.

Anyways, normally this shouldn't really be a problem (normally you don't
want to display a long string of just i or j).

In 1.1 you can P/Invoke to DrawTextEx in user32 (see
http://pinvoke.net/default.aspx/user32/DrawTextEx.html). This is what
the TextRenderer uses.

hth
Ben
Hilton - 17 Sep 2007 07:12 GMT
I definitely see this with some code I wrote - looks pretty bad.  In my
case, the characters get closer together.

> If you draw a string that consists of repeating lower case characters
> 'i' or 'l' or 'j' then starting from 20th character the space between
> characters is more than that before 20th character. I got this with a
> font "Microsoft Sans Serif" size 8.25

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.