return new Size(bounds.Right - bounds.Left + (int)(form.MyAutoScaleFactor.Width * 4), bounds.Bottom - bounds.Top);
但我收到了
的警告Warning 2 Accessing a member on 'NonFullscreen.MessageBoxForm.MyAutoScaleFactor' may cause a runtime exception because it is a field of a marshal-by-reference class C:\Projekti\Skladiscenje\Skladiscenje\NonFullscreen\MessageBoxForm.cs 244 60 NonFullscreen
如何防止运行时异常?
答案 0 :(得分:4)
根据the docs for that warning,这样的事情可能有所帮助(首先提取到局部变量):
var scaleFactor = form.MyAutoScaleFactor;
return new Size(bounds.Right - bounds.Left + (int)(scaleFactor.Width * 4),
bounds.Bottom - bounds.Top);