vb中picture用line画两闭合图形的时候中间多了一条线?
运行代码,调用两个数组,画出图形不一定是矩形,可能是其他形状。ForI=0ToUBound(X,2)-1x1=X(0,I)*(f-100)/(b+d)y1=X(1,I)*...
运行代码,调用两个数组,画出图形不一定是矩形,可能是其他形状。
For I = 0 To UBound(X, 2) - 1
x1 = X(0, I) * (f - 100) / (b + d)
y1 = X(1, I) * (f - 100) / (c + e)
x2 = X(0, I + 1) * (f - 100) / (b + d)
y2 = X(1, I + 1) * (f - 100) / (c + e)
Picture1.Line (x1, y1)-(x2, y2), vbRed
Next I
Picture1.Refresh
DoEvents
Do While U < UBound(z, 2)
x3 = z(0, U) * (f - 100) / (b + d)
y3 = z(1, U) * (f - 100) / (c + e)
x4 = z(0, U + 1) * (f - 100) / (b + d)
y4 = z(1, U + 1) * (f - 100) / (c + e)
Picture1.Line (x3, y3)-(x4, y4), vbBlue
U = U + 1
Loop 展开
For I = 0 To UBound(X, 2) - 1
x1 = X(0, I) * (f - 100) / (b + d)
y1 = X(1, I) * (f - 100) / (c + e)
x2 = X(0, I + 1) * (f - 100) / (b + d)
y2 = X(1, I + 1) * (f - 100) / (c + e)
Picture1.Line (x1, y1)-(x2, y2), vbRed
Next I
Picture1.Refresh
DoEvents
Do While U < UBound(z, 2)
x3 = z(0, U) * (f - 100) / (b + d)
y3 = z(1, U) * (f - 100) / (c + e)
x4 = z(0, U + 1) * (f - 100) / (b + d)
y4 = z(1, U + 1) * (f - 100) / (c + e)
Picture1.Line (x3, y3)-(x4, y4), vbBlue
U = U + 1
Loop 展开
1个回答
展开全部
如果你想画出闭合的图形,数组里存储的点,必须是闭合的,即最后一个点跟第一个点一样,不知道你b,c,d,e,f参数都是什么值,没法运行试试。不过中间的线没有道理
Option Explicit
Private Sub Command1_Click()
Dim z() As Integer
Dim U As Integer, f As Integer, b As Integer, c As Integer, d As Integer, e As Integer
Dim x3 As Integer, y3 As Integer, x4 As Integer, y4 As Integer
ReDim z(1, 4)
f = Picture1.Width
b = 1
c = 1
d = 1
e = 1
z(0, 0) = 0
z(1, 0) = 0
z(0, 1) = 1
z(1, 1) = 0
z(0, 2) = 1
z(1, 2) = 1
z(0, 3) = 0
z(1, 3) = 1
z(0, 4) = 0
z(1, 4) = 0
U = 0
Do While U < UBound(z, 2)
x3 = z(0, U) * (f - 100) / (b + d)
y3 = z(1, U) * (f - 100) / (c + e)
x4 = z(0, U + 1) * (f - 100) / (b + d)
y4 = z(1, U + 1) * (f - 100) / (c + e)
Picture1.Line (x3, y3)-(x4, y4), vbBlue
U = U + 1
Loop
End Sub
效果图
追问
你这个是一个闭合图形,当同时画两个闭合图形的时候就不行了,我也不知道为什么,你可以试试?我给的代码是两个循环一起的哈(参数bcdef可以不要,是因为你数据有点大,我图形在picture里面按比例缩小的参数。)
追答
画闭合图形的程序没有问题,问题出在,1,你不应该Picture1.Refresh这会把原来的线删除
2,数组里面的点数据有问题,我按照你的程序写的没有任何问题
X(0, 0) = 1
X(1, 0) = 1
X(0, 1) = 5
X(1, 1) = 1
X(0, 2) = 5
X(1, 2) = 5
X(0, 3) = 1
X(1, 3) = 5
X(0, 4) = 1
X(1, 4) = 1
z(0, 0) = 2
z(1, 0) = 2
z(0, 1) = 4
z(1, 1) = 2
z(0, 2) = 4
z(1, 2) = 4
z(0, 3) = 2
z(1, 3) = 4
z(0, 4) = 2
z(1, 4) = 2
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询