Hi, i was adding some controls on the main form of my application and on next build I get badly rendered strings on all Infragistics controls, only on runtime: ad design time they are properly rendered. Can somebody tell me where could be the cause and how to solve it?
Thanks
Alessandro
Please clarify what you mean by "badly rendered strings", if possible by posting a screenshot. It is possible that you are referring to the differences between GDI and GDI+; the latter is widely considered to be a buggy implemention although Microsoft's explanation is that the kerning differences are the necessary result of "resolution independence". They explain this in the following KB article
Ok... this is how text on the UltraToolbarsManager is rendered at design time:
and this is how it looks at runtime:
(the text is loaded on the constructor to load localized string)....
I can do better!!! The cause is the OnPaint method of the Splash class. It draws images and text messages to the user. I'm using the TextRenderingHint property of the Graphics class to render the message strings on the splash. The usage is like this:
using (Graphics grph = pArgs.Graphics) { grph.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
. . .
}
If the line with TextRenderingHint is commented, there are no problems. The funny thing is that before I never experienced this behavior, with the same code. Any Ideas?
Hi,
I could be wrong, but the code you have here seems a bit odd.Why are you using a Using statement here? You are getting the Graphics object from the event args, so this is the Graphics of the form. You should not need a Using statement here and doing so might be dangerous, because you are probably causing this Graphics object to get disposed. I don't know what effect this would have on the form, but it seems like a really bad idea.
I would get rid of the Using statement and also make sure you set the TextRenderingHint back to it's original value after you are done doing what you need to do. It's good practice to enclose code like this in a try...finally and restore the graphics objects to it's original settings in the finally block.
Yes, you are right... actually is a copy and paste code I found on the web... but is not the cause of font bad rendering. I tried to set back the TextRendering to SystemDefault but nothing happens. If I don't use it it's all OK. The more strange thing is that I had this same code for almost a year and never gave problems.
Cheers,
Hi, a stupid try I've made, to use a CreateGraphics() insted reusing the one from PaintEventArgs, resolved the issue... Actually I don't understand what's happening in the background... but it works. I've made:
protected override void OnPaint(PaintEventArgs pArgs) { base.OnPaint(pArgs); using (Graphics graph = this.CreateGraphics()) { TextRenderingHint orighint = graph.TextRenderingHint;
. . . . .
Maybe this is heresy, but it seems to work... (I'm not very very skilled in Graphics usage)....
Hi Alessandro,
I guess using CreateGrpahics must be creating a clone of the form's Graphics object. But I think that's probably just further evidence that your original code was altering the form's Graphics object in some way and not properly restoring it to it's original state.