Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1019329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:59:46+00:00 2026-05-16T10:59:46+00:00

I’m developing a .net 3.5 Win Forms program and I’ve run into an interesting

  • 0

I’m developing a .net 3.5 Win Forms program and I’ve run into an “interesting” problem with text drawing.

I’m implementing a text editing control and it draws text with DrawString() and StringFormat.GenericTypographic (henceforth, GT). As the user types, whole words (or groups of words) earlier in the line are moving subtly left and right at random.

It seems likely to be rounding errors – an affected block looks to shift one pixel in the horizontal plane as letters are added to the line’s end. If I use StringFormat.GenericDefault (GD) this doesn’t happen, but characters are rendered less accurately and this isn’t acceptable.

I reasoned that I could slowly change GD into GT (the settings for each are discussed in MSDN and can obviously be examined in the debugger) and see which FormatFlags or other setting was causing this and go from there. However, if I take a copy of GD, change all the properties so it is identical to GT, the character placement is quite different – the behaviour of these two supposedly identical objects is obviously not the same.

Like too many things IMHO, .net Reflector shows that StringFormat is just a wrapper for a non-managed object and I can only assume that not all the properties of this are exposed to .net software.

Can anybody suggest anything that might help me? I’m aware that TextRenderer might provide an alternative method for rendering but I discounted that earlier in my design process (although I can’t actually remember what the problem was now…).

Edit

The code I’m using for rendering is as follows:

sForm = new StringFormat(StringFormat.GenericTypographic);
sForm.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;

using (SolidBrush brush = new SolidBrush(frmt.ForegroundColour))
  context.DrawString(line.Text, frmt.DisplayFont, brush, new PointF(horizontal, height), sForm);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:59:47+00:00Added an answer on May 16, 2026 at 10:59 am

    Well, I’ve solved the problem. It’s not the way I wanted to do it, but for reference, I’ve done it like this:

    I already have code that calculates a bounding box for each word (for working out the caret position when clicking in the control and for displaying justified text), so rather than drawing the entire line in one go, I’m now drawing each word separately.

    It seems wasteful to continually call DrawString() for each word (when it can cope with whole multi-line blocks in one go), but the program remains pretty fast.

    Now if only I could work out why it seems to want to change the kerning for individual letters within a word as the word grows…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.