2个回答
展开全部
窗体中添加一个Command1按钮,复制如下代码,点击命令按钮后,清屏然后随机画出20条线段
Private Sub Command1_Click()
Dim I As Integer, X1 As Integer, Y1 As Integer, X2 As Integer, Y2 As Integer
Dim ColorR As Long, ColorG As Long, ColorB As Long, DrawColor As Long
Randomize
Cls
ScaleMode = 3 ' 设置 ScaleMode 为像素
DrawMode = 13 '输出外观(前景色与背景色的操作方式)
DrawStyle = 0 '线条样式
'【0(缺省值)实线,1 虚线,2 点线,3 点划线,4 双点划线,5 无线,6 内收实线】
For I = 1 To 20
X1 = Rnd * Me.ScaleWidth
Y1 = Rnd * Me.ScaleHeight
X2 = Rnd * Me.ScaleWidth
Y2 = Rnd * Me.ScaleHeight
DrawWidth = Rnd * 10 + 1 '线条宽度,数值可选为1~32767,不过太大了就无法分辨了
ColorR = Rnd * 256
ColorG = Rnd * 256
ColorB = Rnd * 256
DrawColor = (((256 * ColorR) + ColorG) * 256) + ColorB
ForeColor = DrawColor
Line (X1, Y1)-(X2, Y2)
Next
End Sub
Private Sub Command1_Click()
Dim I As Integer, X1 As Integer, Y1 As Integer, X2 As Integer, Y2 As Integer
Dim ColorR As Long, ColorG As Long, ColorB As Long, DrawColor As Long
Randomize
Cls
ScaleMode = 3 ' 设置 ScaleMode 为像素
DrawMode = 13 '输出外观(前景色与背景色的操作方式)
DrawStyle = 0 '线条样式
'【0(缺省值)实线,1 虚线,2 点线,3 点划线,4 双点划线,5 无线,6 内收实线】
For I = 1 To 20
X1 = Rnd * Me.ScaleWidth
Y1 = Rnd * Me.ScaleHeight
X2 = Rnd * Me.ScaleWidth
Y2 = Rnd * Me.ScaleHeight
DrawWidth = Rnd * 10 + 1 '线条宽度,数值可选为1~32767,不过太大了就无法分辨了
ColorR = Rnd * 256
ColorG = Rnd * 256
ColorB = Rnd * 256
DrawColor = (((256 * ColorR) + ColorG) * 256) + ColorB
ForeColor = DrawColor
Line (X1, Y1)-(X2, Y2)
Next
End Sub
DFRobot
2024-11-10 广告
2024-11-10 广告
图形化编程是一种直观的编程方式,它通过拖拽图形化的编程积木来构建程序,降低了编程的学习门槛。在上海智位机器人股份有限公司,我们致力于将图形化编程应用于机器人教育等领域,使学习者能够以更加轻松、有趣的方式掌握编程技能。我们的图形化编程平台界面...
点击进入详情页
本回答由DFRobot提供
展开全部
代码可以放在Timer里,每间隔一定时间就重新产生20条。
或放在Form_Click里,每次鼠标单击就能产生20条。
cls
randomize
for i = 1 to 20
x1=fix(rnd*form1.scalewidth)
y1=fix(rnd*form1.scaleheight)
x2=fix(rnd*form1.scalewidth)
y2=fix(rnd*form1.scaleheight)
r=fix(rnd*256)
g=fix(rnd*256)
b=fix(rnd*256)
line(x1,y1)-(x2,y2),rgb(r,g,b)
next i
Li.YQ@163.com
或放在Form_Click里,每次鼠标单击就能产生20条。
cls
randomize
for i = 1 to 20
x1=fix(rnd*form1.scalewidth)
y1=fix(rnd*form1.scaleheight)
x2=fix(rnd*form1.scalewidth)
y2=fix(rnd*form1.scaleheight)
r=fix(rnd*256)
g=fix(rnd*256)
b=fix(rnd*256)
line(x1,y1)-(x2,y2),rgb(r,g,b)
next i
Li.YQ@163.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询