vb.net 画图问题
要解决的问题是这样我们有一个已经生成好的随机二维数组a(n,n),ps:a(n,n)对角线都等于0,别的元素等于1或0我们有一个按钮buttuon1和一个gruopbox...
要解决的问题是这样
我们有一个已经生成好的随机二维数组 a(n,n),ps: a(n,n)对角线都等于0,别的元素等于1或0
我们有一个按钮 buttuon1和一个gruopbox1
在按button1的时候在groupbox1里面画图
主要思路是这样的
先在groupbox1 画n个小圆 (小圆旁边显示序号)
如果a(i,j)=1 则 把第i个点和第j个点连接
要实现的效果是这样的 展开
我们有一个已经生成好的随机二维数组 a(n,n),ps: a(n,n)对角线都等于0,别的元素等于1或0
我们有一个按钮 buttuon1和一个gruopbox1
在按button1的时候在groupbox1里面画图
主要思路是这样的
先在groupbox1 画n个小圆 (小圆旁边显示序号)
如果a(i,j)=1 则 把第i个点和第j个点连接
要实现的效果是这样的 展开
1个回答
展开全部
Public Class Form1
Public myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Public formGraphics As System.Drawing.Graphics
Private r As Integer = 5 '点半径
Private data(10) As System.Drawing.Point '数据点
Private link(10, 10) As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each pt In data
formGraphics.DrawEllipse(myPen, New Rectangle(pt.X, pt.Y, r, r))
Next
DrawLink(data)
End Sub
Private Sub DrawLink(data() As System.Drawing.Point)
Dim pt1, pt2 As System.Drawing.Point
For i = 0 To UBound(link)
For j = 0 To UBound(link, 2) - i - 1
If link(i, j) = 1 Then
pt1.X = data(i).X + r / 2 : pt1.Y = data(i).Y + r / 2
pt2.X = data(j).X + r / 2 : pt2.Y = data(j).Y + r / 2
formGraphics.DrawLine(myPen, pt1, pt2)
End If
Next j
Next i
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim i, j As Integer
formGraphics = GroupBox1.CreateGraphics()
r = 10
'生成一些测试数据
Randomize()
For i = 0 To UBound(data)
data(i).x = Rnd() * 400
data(i).y = Rnd() * 200
Next
'生成一些测试边
For i = 0 To UBound(link)
For j = 0 To UBound(link, 2) - i - 1
link(i, j) = Int(Rnd() * 2)
Next j
Next i
End Sub
Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
myPen.Dispose()
formGraphics.Dispose()
End Sub
End Class
追问
能用扣扣联系吗? 代码提示错误 打扰您了
扣扣:236099765
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询