且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何解决此问题:参数无效

更新时间:2022-10-31 18:03:53

请对调用的所有三个参数进行完整检查:image(应该是有效的,不能为null ),匹配正宽度和高度.由于涉及设计模式,因此在调试器中很难做到这一点.要调查这种情况,可以使用类System.Diagnostics.EventLog,请参见 http://msdn .microsoft.com/en-us/library/system.diagnostics.eventlog.aspx [
现在,可能的分辨率.设计时可能是一场灾难,很难调试-不要过度使用它.检查属性System.ComponentModel.Component.DesignMode的值,如果在DesignModetrue时执行了控制方法,请避免进行任何详尽的处理或有问题的处理.您的设计模式应仅允许使用正确的边界正确渲染控件,并允许使用PropertyGrid编辑属性.应避免所有仅在应用程序执行模式(而非设计模式)中有用的过多事件处理.

请参阅 http://msdn.microsoft.com/en-us/library/system .componentmodel.component.designmode.aspx [ ^ ].

-SA
Please do some sanity check of all of three parameters of the call: image (should be valid, not null), matching positive width and height. This is hard to do under debugger as Design mode is involved. To investigate the situation, you can use the class System.Diagnostics.EventLog, see http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[^].

You will get all the log information in the system log where you can examine it using the "Event Log" viewer, using "Eventvwr.msc".

Now, the possible resolution. Design-time can be a disaster, very hard to debug — don''t overuse it. Check up the value of the property System.ComponentModel.Component.DesignMode and avoid any extensive or questionable processing if your control methods are executed when the DesignMode is true. Your design mode should only allow to render your control correctly with correct bounds and allow for editing of the properties using the PropertyGrid. All excessive event processing useful only in application execution mode (not design mode) should be avoided.

See http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode.aspx[^].

—SA


@ SAKryukov -感谢您的快速回复.我很感激.

@SAKryukov - Thank you for the quick reply. I appreciate it.

报价:

请对调用的所有三个参数进行完整检查:图像(应该是有效的,不能为null),匹配正宽度和高度.

Please do some sanity check of all of three parameters of the call: image (should be valid, not null), matching positive width and height.



我已经检查了代码中的图片:



I have checked the image in the code:

If PImg Is Nothing = False


而且我还用MsgBox检查了高度和宽度:


And I have also checked Height and Width with MsgBox:

MsgBox ("Height is : " + e.ClipRectangle.Height.ToString)
' MsgBox returns the correct value : 42 in this case



但是,在您的帮助下,我当然找到了解决方案.
你给我一个主意.

我将此代码放在OnPaint Sub中.它检查程序是否处于设计模式.



But I have found a solution, of course, with your help.
You gave me an idea.

I put this code in the OnPaint Sub. It checks if the program is in Design Mode or not.

' Using Control.DesignMode
If Me.DesignMode = True Then
' Do some stuff like : Draw image without using e.ClipRectangle, or something else
Else ' Running, draw images correctly
Dim CImg As New Bitmap (PImg, e.ClipRectangle.Width - 2, e.ClipRectangle.Height - 2)
' ... ... ...
End If



而且它可以正常工作.
您使用Control.DesingMode的想法很棒.
这使我可以从PropertyGrid
编辑属性
我为你的ansewr投了5票.非常感谢.



And it works without any error.
Your idea to using a Control.DesingMode is great.
This allow me to edit properies from the PropertyGrid

I voted 5 for your ansewr. Thanks a lot.