vb.net 有一个功能实现的不理想 但不知道怎么解决掉
我想在groupBox中生成10跳线,其中已经先画出了一条,然后根据这条通过for循环生出其他的线,但是循环后只出来一条线DimstartLineYAsInteger=L...
我想在groupBox中生成10跳线 ,其中已经先画出了一条,然后根据这条通过for循环生出其他的线,但是循环后只出来一条线
Dim startLineY As Integer = LineShape2.StartPoint.Y '获取当前横线的起始Y坐标
Dim endLineY As Integer = LineShape2.EndPoint.Y '获取当前横线的终点Y坐标
Dim startLineX As Integer = LineShape2.StartPoint.X
Dim endLineX As Integer = LineShape2.EndPoint.X
Dim lineNum As Integer
Dim sctr As New ShapeContainer
For lineNum = 0 To 10
Dim line As New PowerPacks.LineShape(sctr)
line.Y1 = line.Y1 + (startLineY + 20)
line.X1 = startLineX
line.Y2 = line.Y2 + (endLineY + 20)
line.X2 = endLineX
GroupBox1.Controls.Add(sctr)
Next
我尝试把Dim sctr As New ShapeContainer放到for循环的里面 ,这样每循环一次就会新生成一个sctr对象,但还是不行。问题到底出到哪里了呢,应该怎么解决呢 。 展开
Dim startLineY As Integer = LineShape2.StartPoint.Y '获取当前横线的起始Y坐标
Dim endLineY As Integer = LineShape2.EndPoint.Y '获取当前横线的终点Y坐标
Dim startLineX As Integer = LineShape2.StartPoint.X
Dim endLineX As Integer = LineShape2.EndPoint.X
Dim lineNum As Integer
Dim sctr As New ShapeContainer
For lineNum = 0 To 10
Dim line As New PowerPacks.LineShape(sctr)
line.Y1 = line.Y1 + (startLineY + 20)
line.X1 = startLineX
line.Y2 = line.Y2 + (endLineY + 20)
line.X2 = endLineX
GroupBox1.Controls.Add(sctr)
Next
我尝试把Dim sctr As New ShapeContainer放到for循环的里面 ,这样每循环一次就会新生成一个sctr对象,但还是不行。问题到底出到哪里了呢,应该怎么解决呢 。 展开
2个回答
展开全部
因为你循环里面的坐标点一直没改变,线都画在了同一个坐标点,看起来就只有一条了!你每次循环,都要在循环内改变新的坐标点,把线画在不同的地方。例如下面的演示代码:在GroupBox1上连续划横线,横线的高度距离为20(h),超出GroupBox1的高度范围后循环退出,停止划线。另外,GroupBox1.Controls.Add(sc)应该放在循环外面,昨晚忘记改了!
Dim sc As New ShapeContainer
Dim ps As LineShape, h As Integer = 20
For i As Integer = 1 To (GroupBox1.Height \ h)
ps = New LineShape(sc)
ps.Y1 = h * i : ps.X1 = 0
ps.Y2 = ps.Y1 : ps.X2 = GroupBox1.ClientSize.Width - 8
Next
GroupBox1.Controls.Add(sc)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询