在 GDI+ “参数无效。”设置pen.Width

发布于 2024-08-21 18:00:20 字数 1146 浏览 6 评论 0原文

我有一个System.Drawing.Pen _pen

当在某些迭代中设置 _pen.Width = 3 时,它会给我:

System.ArgumentException 
  Message="Parameter is not valid."
  Source="System.Drawing"  - System.Drawing.dll
  StackTrace:
       at System.Drawing.Pen.set_Width(Single value)
       at MyProject.ctlPanneauGraphique.CustomLine.set_BorderWidth(Int32 value) in 
       ....
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at MySolution.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

什么以及为什么?

I have a System.Drawing.Pen _pen.

When in some iterations is setting _pen.Width = 3 it gives me:

System.ArgumentException 
  Message="Parameter is not valid."
  Source="System.Drawing"  - System.Drawing.dll
  StackTrace:
       at System.Drawing.Pen.set_Width(Single value)
       at MyProject.ctlPanneauGraphique.CustomLine.set_BorderWidth(Int32 value) in 
       ....
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at MySolution.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

What and why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

也只是曾经 2024-08-28 18:00:20

您正在处理 _pen 变量吗?

如果不是,这可能表明存在资源泄漏问题,正如您所怀疑的那样。

如果是,这可能表明您正在访问已处置的实例。 GDI 对象在被释放后使用时通常会抛出 ArgumentException。

Are you disposing the _pen variable?

If not, this may indicate a resource leak problem as you have suspected.

If yes, this may indicate that you are accessing a disposed instance. GDI objects often throw ArgumentException when used after they have been disposed.

智商已欠费 2024-08-28 18:00:20

您如何初始化 _pen 变量?根据 MSDN 文档,如果您是使用 Pens 类来初始化变量,您将得到一个不可变的 Pen,其 Width 参数无法设置。尝试这样做将导致抛出 ArgumentException,这正是您所看到的。

How are you initializing the _pen variable? According to MSDN documentation, if you are using the Pens class to initialize your variable, you will get an immutable Pen, whose Width parameter cannot be set. Attempting to do so will result in an ArgumentException being thrown, which is exactly what you are seeing.

ゃ懵逼小萝莉 2024-08-28 18:00:20

我开始认为这是由于内存泄漏问题造成的。显然,操作系统无法创建超过 10.000 个 GDI+ 对象...

在执行一些分析后,我检测到应用程序中存在巨大的内存泄漏,因此错误来自那里。

I started supposing that comes from a memory leak problem. Apparently the OS cant create more that 10.000 GDI+ objects...

After some analysis was performed I detected a huge memory leack in the application, so the error came from there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文