-
Notifications
You must be signed in to change notification settings - Fork 74
Description
From @ckak07
Hello. I am using the LongText
property to visualize the connection state of my interfaces to the users. But sometimes the position of the text is incorrect:

In 95% of the time the position is correct. I am not able to tell you the trigger which causes this. This is the correct position:

Can you tell me what my problem is?
I am using this code to set the connection state string:
LongForeColor = connectionStateTextColor;
LongText = connectionStateText; TreeView.Refresh();
Every time I get this error I also get the following Exception:
Exception thrown: 'System.ArgumentException' in System.Drawing.dll
Ungültiger Parameter.
Extracted embedded document 'System.Drawing\Graphics.cs' to 'C:\Users\wieckowskic\AppData\Local\Temp.vsdbgsrc\0b9159ab0ba1693197c456715007381a34512a2d7e5ec0069dfcb48674a027cd\Graphics.cs'
Extracted embedded document 'Krypton.Toolkit\AccurateText.cs' to 'C:\Users\wieckowskic\AppData\Local\Temp.vsdbgsrc\c5005e343da174ed67ae8cb92cccbefbeb8e9be31c7bf6dcfd50f23c496d886e\AccurateText.cs'
and this is the call stack:

I could debug the error and I found out that the following line returns the value '2':
int num = SafeNativeMethods.Gdip.GdipMeasureString(new HandleRef(this, NativeGraphics), text, text.Length, new HandleRef(font, font.NativeFont), ref layoutRect, new HandleRef(stringFormat, stringFormat?.nativeFormat ?? IntPtr.Zero), ref boundingBox, out codepointsFitted, out linesFilled);
Looking at the API reference of this native call showed me that the value '2' means 'InvalidParameter = 2'. Looking at the parameters of this call showed me that font.NativeFont
is null. So this is the reason why I get this exception. I don't know what is causing the error and how I can fix it.
I am using this option in my manifest file:
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
Maybe this could help you to figure out what the problem is.
I set a breakpoint to System.Drawing.Font.Dispose
and the breakpoint hits after some time (round about 10 Minutes). This is the call stack:

The application runs without any interaction. Why is krypton disposing the font?
I found the bug. There is an bug in the class PaletteMicrosoft365Base
. When the event OnUserPreferenceChanged
is fired the method DefineFonts
will be called. the first line of this method calls DisposeFonts();
. During this time the font.nativeFont
become null and I get the exception. Using Krypton.Toolkit.KryptonCustomPaletteBase
and setting the BasePalette
solves this problem.