简单的图形导致中断模式 [英] Simple graphics causing break mode
本文介绍了简单的图形导致中断模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的onPaint覆盖中的SetStyle和e.Graphics将无法一起工作,并且正在将我的应用程序发送到模糊的中断模式。
这是代码:
Hi,
SetStyle and e.Graphics in my onPaint override just won't work together and are sending my application into an ambiguous break mode.
Here's the code:
Public Class CustomProgressbar
Inherits Control
Private loaded As Boolean = False
Public Sub New()
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
End Sub
Public Sub init()
loaded = True
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
If Not loaded Then Return
Using g As Graphics = e.Graphics
' g.FillRectangle(New LinearGradientBrush(New Rectangle(0, 0, Width + 1, Height + 1), GraphicsUtils._c(178, 178, 178), GraphicsUtils._c(140, 140, 140), 90), New Rectangle(0, 0, Width + 1, Height + 1))
' g.FillRectangle(New LinearGradientBrush(New Rectangle(1, 1, Width - 2, Height - 2), GraphicsUtils._c(242, 242, 242), GraphicsUtils._c(226, 226, 226), 90), New Rectangle(1, 1, Width - 2, Height - 2))
' If Not _v = 0 Then
' Dim c As Color = GraphicsUtils._c(150, 0, 255)
' Dim h As HslColor = HslColor.fromColor(c)
' g.FillRectangle(New LinearGradientBrush(New Rectangle(2, 2, _v, Height - 5), (h - New HslColor(0, 0, 0.037)).toColor(), (h - New HslColor(0, 0, 0.206)).toColor(), 90), New Rectangle(2, 2, _v, Height - 5))
' g.DrawLine(GraphicsUtils._p((h - New HslColor(0, 0, 0.02)).toColor()), 2, Height - 3, _v + 1, Height - 3)
' End If
End Using
End Sub
我的尝试:
如果我删除Using语句,它可以正常工作。如果我删除SetStyle语句,它也可以正常工作。我已经尝试将我调用init()的时间更改为表单的加载事件,单击按钮,但没有任何效果。
What I have tried:
If I remove the Using statement, it works fine. If I remove the SetStyle statement, it works fine too. I've tried changing the time I call init() to the load event of the form, to a button click, yet nothing works.
推荐答案
你得到了图形来自系统的(e.Graphics),但是你用'使用'('使用'处理使用的对象)来处理它。所以,不要使用'使用',但是例如:
You get the graphics (e.Graphics) from the system but you're disposing it with 'Using' ('Using' disposes the object used). So, don't use 'Using' but for example:
Dim g As Graphics = e.Graphics
这篇关于简单的图形导致中断模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文