VB2005 在picturebox控件的click中绘图的问题
DimmAsIntegerDimstrBrushAsNewDrawing.SolidBrush(Drawing.Color.Black)DimstrFontAsNewSy...
Dim m As Integer
Dim strBrush As New Drawing.SolidBrush(Drawing.Color.Black)
Dim strFont As New System.Drawing.Font("新宋体", 10)
Dim strFormat As New Drawing.StringFormat()
Private Sub picturebox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picturebox.Click
m += 1
Dim mybitmap As New Drawing.Bitmap(100, 48)
Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(mybitmap)
Me.picReady.Image = mybitmap
Dim pointarray As Drawing.Point() = {New Drawing.Point(2, 24), New Drawing.Point(25, 2), New Drawing.Point(75, 2), New Drawing.Point(98, 24), New Drawing.Point(75, 46), New Drawing.Point(25, 46)}’填充区域
If m Mod 2 Then 'picturebox控件单击奇数次
g.FillPolygon(Drawing.Brushes.WhiteSmoke, pointarray)
Else
g.FillPolygon(Drawing.Brushes.blue, pointarray)
End If
g.DrawString("机器就绪", strFont, strBrush, 23, 19, strFormat)
End Sub
如上代码,实现picturebox点击后其上绘制的区域填充颜色白色与蓝色循环的功能,若新建一个应用程序项目,添加如上代码后能实现功能,可是为什么在我的项目中,庞大的代码中的这一部分就不起作用了呢?我还要怎么做?请高手示下!!谢谢!
注意:我的程序中已经有了该picturebox的paint事件,是不是他俩冲突啊?
回复wdf2:这个错误是不会犯的啦!
回复dc:我这段代码的意思是想让picturebox上所绘六边形区域中填充颜色,在每单击控件一次后发生白色与蓝色的交替变化,出现的问题就是:没达到这个效果,一点反应也没有,经过验证确实是因为我的程序中已经存在了picturebox_paint时间,可是他们为什么不能共存呢?
后记:通过我不断地试验,找到了症结:click中建立的bitmap与该控件的paint中fillpolygon冲突,修改后click中只保留以下:
Private Sub picturebox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picturebox.Click
Dim mybitmap As New Drawing.Bitmap(100, 48)
m += 1
Me.picturebox.Image = mybitmap
End Sub
同事在paint中添加代码
If m Mod 2 Then 'picturebox控件单击奇数次
g.FillPolygon(Drawing.Brushes.WhiteSmoke, pointarray)
Else
g.FillPolygon(Drawing.Brushes.blue, pointarray)
End If
并删除paint中原有的fillpolygon()
只是,我还不明白,为什么非要如此呢? 展开
Dim strBrush As New Drawing.SolidBrush(Drawing.Color.Black)
Dim strFont As New System.Drawing.Font("新宋体", 10)
Dim strFormat As New Drawing.StringFormat()
Private Sub picturebox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picturebox.Click
m += 1
Dim mybitmap As New Drawing.Bitmap(100, 48)
Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(mybitmap)
Me.picReady.Image = mybitmap
Dim pointarray As Drawing.Point() = {New Drawing.Point(2, 24), New Drawing.Point(25, 2), New Drawing.Point(75, 2), New Drawing.Point(98, 24), New Drawing.Point(75, 46), New Drawing.Point(25, 46)}’填充区域
If m Mod 2 Then 'picturebox控件单击奇数次
g.FillPolygon(Drawing.Brushes.WhiteSmoke, pointarray)
Else
g.FillPolygon(Drawing.Brushes.blue, pointarray)
End If
g.DrawString("机器就绪", strFont, strBrush, 23, 19, strFormat)
End Sub
如上代码,实现picturebox点击后其上绘制的区域填充颜色白色与蓝色循环的功能,若新建一个应用程序项目,添加如上代码后能实现功能,可是为什么在我的项目中,庞大的代码中的这一部分就不起作用了呢?我还要怎么做?请高手示下!!谢谢!
注意:我的程序中已经有了该picturebox的paint事件,是不是他俩冲突啊?
回复wdf2:这个错误是不会犯的啦!
回复dc:我这段代码的意思是想让picturebox上所绘六边形区域中填充颜色,在每单击控件一次后发生白色与蓝色的交替变化,出现的问题就是:没达到这个效果,一点反应也没有,经过验证确实是因为我的程序中已经存在了picturebox_paint时间,可是他们为什么不能共存呢?
后记:通过我不断地试验,找到了症结:click中建立的bitmap与该控件的paint中fillpolygon冲突,修改后click中只保留以下:
Private Sub picturebox_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picturebox.Click
Dim mybitmap As New Drawing.Bitmap(100, 48)
m += 1
Me.picturebox.Image = mybitmap
End Sub
同事在paint中添加代码
If m Mod 2 Then 'picturebox控件单击奇数次
g.FillPolygon(Drawing.Brushes.WhiteSmoke, pointarray)
Else
g.FillPolygon(Drawing.Brushes.blue, pointarray)
End If
并删除paint中原有的fillpolygon()
只是,我还不明白,为什么非要如此呢? 展开
2个回答
展开全部
LZ能描述下这部分代码运行的时,具体出现了什么问题吗,
我给个单击时改变窗体颜色的代码。LZ看看
private sub form_click()
refresh
end sub
private sub form_paint()
static num as integer
x=scalewidth/2
y=scaleheight/2
radius=scalewidth/4
filstyle=vbFSSslid
num=num+1
num=num mod 2
selext case num
case 0
fillcolor=QBcolor(0)
circle(x,y),radius
case 1
filecolor=QBcolor(1)
circe(x,y),radius
end select
end sub
代码是直接在回答问题的文本框里打的 考虑可能有不当的地方
代码都比较简单,就没加注释,LZ将就看下
我给个单击时改变窗体颜色的代码。LZ看看
private sub form_click()
refresh
end sub
private sub form_paint()
static num as integer
x=scalewidth/2
y=scaleheight/2
radius=scalewidth/4
filstyle=vbFSSslid
num=num+1
num=num mod 2
selext case num
case 0
fillcolor=QBcolor(0)
circle(x,y),radius
case 1
filecolor=QBcolor(1)
circe(x,y),radius
end select
end sub
代码是直接在回答问题的文本框里打的 考虑可能有不当的地方
代码都比较简单,就没加注释,LZ将就看下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询