vb 2013上怎么用 picturebox 画圆?(不要百度的答案)我为什么用不了Picture?求指点。
vb2013上怎么用picturebox画圆?(不要百度的答案)我为什么用不了Picture?求指点。...
vb 2013上怎么用 picturebox 画圆?(不要百度的答案)我为什么用不了Picture?
求指点。 展开
求指点。 展开
展开全部
你的代码是vb6.0的格式,在vb2013的net模式下是无法通过调试的
vb2013中要用GDI+的方法,比如
Public Class Form1
Dim wid As Integer
Dim hgt As Integer
Dim bm As Bitmap
Dim g As Graphics
'下面是画坐标轴
Private Function draw_coordinate() As Boolean '画坐标轴
g.DrawLine(Pens.Red, -250, 0, 250, 0)
g.DrawLine(Pens.Green, 0, -250, 0, 250)
'画y轴刻度
For i = -250 To 250 Step 2
g.DrawLine(Pens.Green, -1, i, 1, i)
Next
For i = -250 To 250 Step 2
g.DrawLine(Pens.Red, i, -1, i, 1)
Next
PictureBox1.Image = bm
PictureBox1.Refresh()
Return True
End Function
'下面是画点(也是实心圆)
Private Function DrawCircle(ByVal cp As Point, ByVal radius As Integer, ByVal color As Brush) As Boolean '画实心圆
Dim rect As Rectangle = New Rectangle(cp.X - radius, cp.Y - radius, 2 * radius, 2 * radius)
g.DrawEllipse(Pens.Red, rect)
g.FillEllipse(color, rect)
PictureBox1.Image = bm
PictureBox1.Refresh()
Return True
End Function
Public Sub DrawEmptyCircle(ByVal mypen As Pen, ByVal Zeropoint As Point, ByVal r As Single) '画空心圆
'画圆
'Zeropoint:圆心,所在坐标系的原点为窗体左上角,向下向右为Y、X轴正方向。
'r:半径
g.DrawEllipse(mypen, Zeropoint.X - r, Zeropoint.Y - r, 2 * r, 2 * r)
PictureBox1.Image = bm
PictureBox1.Refresh()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
wid = PictureBox1.ClientSize.Width
hgt = PictureBox1.ClientSize.Height
bm = New Bitmap(wid, hgt)
g = Graphics.FromImage(bm)
g.TranslateTransform(250, 250) '坐标平移
g.ScaleTransform(1, -1) 'X轴不变,反转Y轴
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '演示画轴,画圆
draw_coordinate()
' DrawCircle(New Point(0, 0), 100, New System.Drawing.SolidBrush(Color.Red))'画实心圆
DrawEmptyCircle(New Pen(Color.Red), New Point(0, 0), 100) '画空心圆---圆心(0,0),半价100
End Sub
End Class
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询