Note that there are some explanatory texts on larger screens.

plurals
  1. PO.net DrawString / StringFormat problem
    primarykey
    data
    text
    <p>I'm developing a .net 3.5 Win Forms program and I've run into an "interesting" problem with text drawing.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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...).</p> <p><strong>Edit</strong></p> <p>The code I'm using for rendering is as follows:</p> <pre><code>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); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload