重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
在窗体上拉一个Timer控件,enabled设为true,Interval设为20。完整代码如下: Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
成都创新互联专注于成都做网站、成都网站建设、网页设计、网站制作、网站开发。公司秉持“客户至上,用心服务”的宗旨,从客户的利益和观点出发,让客户在网络营销中找到自己的驻足之地。尊重和关怀每一位客户,用严谨的态度对待客户,用专业的服务创造价值,成为客户值得信赖的朋友,为客户解除后顾之忧。
Dim formGraphics As System.Drawing.Graphics
Dim num As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Refresh() '清屏
formGraphics = Me.CreateGraphics()
formGraphics.DrawEllipse(myPen, New Rectangle(100, 100, num, num)) '在坐标(100,100)的位置画圆
If num 200 Then '如果大于200则停止画圆
myPen.Dispose()
formGraphics.Dispose()
Timer1.Enabled = False
Else
num = num + 1
End If
End Sub
VB.net与VB不同。
VB.net已经有专门绘图的类。
可以定义笔刷然后用Drawing类中的方法绘制。
Private Sub DrawEllipse()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawEllipse(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
Private Sub DrawRectangle()
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics as System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawRectangle(myPen, New Rectangle(0,0,200,300))
myPen.Dispose()
formGraphics.Dispose()
End Sub
Paint事件是在控件需要重画时发生,就比如说窗体的Paint事件,只要窗体被其他窗口覆盖后又被重新显示时就会触发Paint事件
没有看到其他代码,暂无法判断哪里有问题
希望回答对你有帮助
参考一下下面这段代码:
‘ 首先picturebox1 加载一张图像
FolderBrowserDialog1.Description = "选择图片文件夹导入图片"
FolderBrowserDialog1.ShowDialog()
path = FolderBrowserDialog1.SelectedPath()
If path = "" Then Return
strSrcFile = Dir(path "\*.tif")
PictureBox1.Image = Image.FromFile(path "\" strSrcFile)
’ 然后再在picturebox1中用graphic画图而不清空原图像
' 建立一个画图对象
Dim g As Graphics = Me.PictureBox1.CreateGraphics
‘ 定义画笔
Dim myPen As System.Drawing.Pen = New System.Drawing.Pen(Color.Blue)
’ 画出矩形框并且填充颜色(颜色保持50%的透明度,使得下面原来的图片背景能看得到)
g.DrawRectangle(myPen, New System.Drawing.Rectangle(50, 50, 30, 20))
g.FillRectangle(New SolidBrush(Color.FromArgb(50, Color.YellowGreen)), New System.Drawing.Rectangle(50, 50, 30, 20))
' 最后释放画图对象
g.Dispose()
效果大致如下图所示:
dim myGraphics as new
System.Drawing .Graphics
Dim myStartPoint As New Point(4, 2)
Dim myEndPoint As New Point(12, 6)
myGraphics.DrawLine(myPen, myStartPoint, myEndPoint)