VB6在picturebox里用GDI+绘图,为什么在绘图之前调用cls方法会导致图形不显示??如何实现预期效果?
代码如下[code]OptionExplicitDimgraphicsAsLongDimpenAsLongPrivateSubForm_Load()Picture.Aut...
代码如下
[code]
Option Explicit
Dim graphics As Long
Dim pen As Long
Private Sub Form_Load()
Picture.AutoRedraw = True
InitGDIPlus
GdipCreateFromHDC Picture1.hDC, graphics
GdipCreatePen1 &HFFFF0000, 1, UnitPixel, pen
Picture1.Cls '如果不加这句,线条没问题。但是添加之后会有问题
GdipDrawLineI graphics, pen, 10, 10, 200, 100
Picture1.Refresh
End Sub
Private Sub Form_Unload(Cancel As Integer)
GdipDeletePen pen '删除这个笔(pen)
GdipDeleteGraphics graphics '释放graphics占用的内存
TerminateGDIPlus
End Sub
[/code]
我想实现的是在timer的每一个周期对picturebox进行重新绘图。那么当然要先cls再画。但是绘图之前的cls为什么会导致失败???应该怎么做? 展开
[code]
Option Explicit
Dim graphics As Long
Dim pen As Long
Private Sub Form_Load()
Picture.AutoRedraw = True
InitGDIPlus
GdipCreateFromHDC Picture1.hDC, graphics
GdipCreatePen1 &HFFFF0000, 1, UnitPixel, pen
Picture1.Cls '如果不加这句,线条没问题。但是添加之后会有问题
GdipDrawLineI graphics, pen, 10, 10, 200, 100
Picture1.Refresh
End Sub
Private Sub Form_Unload(Cancel As Integer)
GdipDeletePen pen '删除这个笔(pen)
GdipDeleteGraphics graphics '释放graphics占用的内存
TerminateGDIPlus
End Sub
[/code]
我想实现的是在timer的每一个周期对picturebox进行重新绘图。那么当然要先cls再画。但是绘图之前的cls为什么会导致失败???应该怎么做? 展开
展开全部
你的画布(Graphics)是用图片框的DC创建的,而cls方法会重置DC,当然不行了,GDI 有专用的清除画布的函数GdipGraphicsClear
追问
如梦方醒啊
Public Declare Function GdipGraphicsClear Lib "gdiplus" (ByVal Graphics As Long, ByVal lColor As Long) As GpStatus
lcolor是什么?背景色吗
这样吗
GdipGraphicsClear graphics, &HFF000000
追答
嗯,lColor是背景色。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询