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)....
Ok! I think I found an example that reproduces the behavior. My application has a splash screen and it seems that this form causes the font to be badly rendered. The strange thing is that in the past the same splash has never caused troubles. The SplashForm is derived fro a ShadowForm:
public class ShadowForm : Form { // class style that adds a shadow to the form private const int CS_DROPSHADOW = 0x00020000;
public ShadowForm() { }
protected override CreateParams CreateParams { [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] get { CreateParams parameters = base.CreateParams; if (DropShadowSupported) { parameters.ClassStyle = (parameters.ClassStyle | CS_DROPSHADOW); } return parameters; } } /// <summary> /// Gets if drop shadow is supported by the OS. /// </summary> public static bool DropShadowSupported { get { return IsWindowsXPOrAbove; } } /// <summary> /// Gets if OS is Windows XP or above. /// </summary> public static bool IsWindowsXPOrAbove { get { OperatingSystem system = Environment.OSVersion; bool runningNT = system.Platform == PlatformID.Win32NT; return runningNT && system.Version.CompareTo(new Version(5, 1, 0, 0)) >= 0; } } }
The call from the program.cs is:
static class Program { //private static Form _splash = null; private static Splash _splash = null; private static Form1 _mainform = null; private static ApplicationContext _context = null; /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); _mainform = new Form1(); _context = new ApplicationContext(); Application.Idle += new EventHandler(OnApplicationIdle); //_splash = new Form(); _splash = new Splash(); _splash.Show(); Application.Run(_context); } static void OnApplicationIdle(object sender, EventArgs e) { if (_context.MainForm == null) { Application.Idle -= OnApplicationIdle; _mainform.PreLoad(); _splash.Close(); _splash.Dispose(); _splash = null; _context.MainForm = _mainform; _context.MainForm.Show(); } } }
If I use a standard form the strings on the menu of the UltraToolbarsManager are well rendered, if I use a Splash form the font they are ugly. If it helps I can e-mail you the VS2008 solution.
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.