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);
关于c# - MyAutoScaleFactor可能会导致运行时异常,因为它是按引用编码类的字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7385730/