问题
In reference from: Main Post
I have the code where i reset the font using:
ListView1.Font.Dispose();
ListView1.Font = new Font("Microsoft Sans Serif", 15F, FontStyle.Regular);
Altough for some reason, at random it gives this error (so not all the time).
System.ArgumentException: Invalid parameter.
at System.Drawing.Font.ToLogFont(Object logFont, Graphics graphics)
at System.Drawing.Font.ToLogFont(Object logFont)
at System.Drawing.Font.ToHfont()
at System.Windows.Forms.Control.FontHandleWrapper..ctor(Font font)
at System.Windows.Forms.Control.get_FontHandle()
at System.Windows.Forms.Control.SetWindowFont()
at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
at System.Windows.Forms.ListView.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ListView.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
My program does the following, Clone lisviews to other listviews etc, so thats why i need to reset the font. Because if i dont it will force all fonts on ListViewItems, altough in about 2% of the tries it crashes with the above error. Quite confusing.
来源:https://stackoverflow.com/questions/60506530/resetting-listview-font-causes-random-crashes