2 taiyang 1435586562 taiyang_1435586562 于 2014.07.08 14:01 提问

VB2010作图时graphics出错

在VB2010中,这段代码中的Dim g2 As graphics ...为什么出错了?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Timer1.Enabled = False
Button1.Text = "hello"
PictureBox1.Image = New Bitmap(PictureBox1.Width, PictureBox1.Height) '将PictureBox1.Image的图像进行定义()
Dim g2 As ** graphics ** = graphics.FromImage(PictureBox1.Image) '定义图像g2, 数据来自于PictureBox1.Image
g2.DrawRectangle(Pens.Black, New Rectangle(0, 0, 20, 20)) '绘制方块函数, 参数 : 笔的颜色, 方块的左下角, 右上角(相对于左下角)
g2.DrawRectangle(Pens.Red, New Rectangle(0, 0, 10, 10))
Dim aa1 As Point 'aa1定义为一个数据结构, 包括x, y两个属性
Dim aa2 As Point
aa1.X = 20
aa2.X = 30
aa1.Y = 50
aa2.Y = 60
g2.DrawLine(Pens.Red, aa1, aa2) '绘制直线:
g2.Dispose()
End Sub

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!