Resetting listview font causes random crashes

做~自己de王妃 提交于 2020-04-18 12:31:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!