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
如何防止运行时异常?
请您参考如下方法:
根据 the docs for that warning ,这样的事情可能会有所帮助(首先提取到局部变量):
var scaleFactor = form.MyAutoScaleFactor;
return new Size(bounds.Right - bounds.Left + (int)(scaleFactor.Width * 4),
bounds.Bottom - bounds.Top);
