画圆 圆心为(350,250)半径为200
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim gr As Graphics = Me.CreateGraphics
gr.DrawEllipse(Pens.Green, 350, 250, 50, 50)
gr.Dispose()
End Sub
End Class
画椭圆 和窗体相同大的椭圆
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim gr As Graphics = Me.CreateGraphics
gr.DrawEllipse(Pens.Red, 0, 0, Me.ClientSize.Width, Me.ClientSize.Height)
gr.Dispose()
End Sub
End Class
画椭圆 改 (跟随窗体大小改变)
Public Class Form1
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Me.Refresh() '刷新
Dim gr As Graphics = Me.CreateGraphics
gr.DrawEllipse(Pens.Red, 0, 0, Me.ClientSize.Width, Me.ClientSize.Height)
gr.Dispose()
End Sub
End Class
画两点之间的线 例如 (100,30)到(500,300)之间的线
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim gr As Graphics = Me.CreateGraphics
gr.DrawLine(Pens.Red, 100, 30, 500, 300)
gr.Dispose()
End Sub
End Class
图片的水平和垂直翻转
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim gr As Graphics = Me.CreateGraphics
Dim img As Image = Image.FromFile("C:\Users\lenovo\Downloads\1.jpg")
gr.DrawImage(img, 0, 0, 100, 100)
gr.DrawImage(img, 0, 220, 100, -100) '垂直翻转
gr.DrawImage(img, 230, 0, -100, 100) '水平翻转
gr.Dispose()
End Sub
End Class
绘制正方形
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim gr As Graphics = Me.CreateGraphics
gr.DrawRectangle(Pens.Red, 130, 50, 300, 300)
gr.Dispose()
End Sub
End Class