如何让用VB制作一个简单的画图板???有简单的制作过程和源代码......求高人指导!
展开全部
Dim a As Double
Dim b As Double
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
a = X
b = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Me.Line (a, b)-(X, Y)
a = X
b = Y
End Sub
Private Sub Label1_Click(Index As Integer) '多放几个背景色不同的label1()控件组
Me.ForeColor = Label1(Index).BackColor
End Sub
Private Sub Text1_Change() '根据输入的数字改变线条宽度
Me.DrawWidth = Val(Text1.Text)
End Sub
'自己刚调试的代码,希望能帮助到你。
Dim b As Double
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
a = X
b = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> 1 Then Exit Sub
Me.Line (a, b)-(X, Y)
a = X
b = Y
End Sub
Private Sub Label1_Click(Index As Integer) '多放几个背景色不同的label1()控件组
Me.ForeColor = Label1(Index).BackColor
End Sub
Private Sub Text1_Change() '根据输入的数字改变线条宽度
Me.DrawWidth = Val(Text1.Text)
End Sub
'自己刚调试的代码,希望能帮助到你。
展开全部
'form1窗体内放置两个TextBox和一个Picturebox
'代码只是演示了简单画图板画线功能,可变色,粗细。
'说明:text1 设置色,text2 设置粗细,Picture1只用作后台画图板,form1作显示图板。
Option ExplicitDim x1 As Long, y1 As Long, x2 As Long, y2 As Long, Col As Long, Bi As Long
Private Sub Form_Load()
Picture1.Visible = False
Picture1.AutoRedraw = True
Picture1.BorderStyle = 0
Picture1.Appearance = 0
Bi = Form1.DrawWidth
Col = vbBlack
Text1.Text = Col
Text2.Text = Bi
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyLButton Then
x1 = X
y1 = Y
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyLButton Then
x2 = X
y2 = Y
Cls
PaintPicture Picture1.Image, 0, 0
Line (x1, y1)-(x2, y2), Col
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyLButton Then
Picture1.Line (x1, y1)-(x2, y2), Col
End If
End Sub
Private Sub Form_Paint()
Picture1.Move 0, 0, Form1.ScaleWidth, Form1.ScaleHeight
End Sub
Private Sub Text1_Change()
On Error Resume Next
Col = CLng(Text1.Text) '设置色
End Sub
Private Sub Text2_Change()
On Error Resume Next
Bi = CLng(Text2.Text) '设置粗细
Form1.DrawWidth = Bi
Picture1.DrawWidth = Bi
End Sub
'代码只是演示了简单画图板画线功能,可变色,粗细。
'说明:text1 设置色,text2 设置粗细,Picture1只用作后台画图板,form1作显示图板。
Option ExplicitDim x1 As Long, y1 As Long, x2 As Long, y2 As Long, Col As Long, Bi As Long
Private Sub Form_Load()
Picture1.Visible = False
Picture1.AutoRedraw = True
Picture1.BorderStyle = 0
Picture1.Appearance = 0
Bi = Form1.DrawWidth
Col = vbBlack
Text1.Text = Col
Text2.Text = Bi
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyLButton Then
x1 = X
y1 = Y
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyLButton Then
x2 = X
y2 = Y
Cls
PaintPicture Picture1.Image, 0, 0
Line (x1, y1)-(x2, y2), Col
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbKeyLButton Then
Picture1.Line (x1, y1)-(x2, y2), Col
End If
End Sub
Private Sub Form_Paint()
Picture1.Move 0, 0, Form1.ScaleWidth, Form1.ScaleHeight
End Sub
Private Sub Text1_Change()
On Error Resume Next
Col = CLng(Text1.Text) '设置色
End Sub
Private Sub Text2_Change()
On Error Resume Next
Bi = CLng(Text2.Text) '设置粗细
Form1.DrawWidth = Bi
Picture1.DrawWidth = Bi
End Sub
追问
您好,我按照你给我的程序运行后只能画出直线,不能画曲线,而且线条的颜色不能改变,只能变线条的粗细,有什么需要改的地方吗?能帮忙指导一下嘛?
追答
col 变量 用来设置颜色。
颜色的值可用:
rgb(0-255,0-255,0-255) 表示,如:rgb(255,0,0) 是红色;rgb(0,255,0)是绿色
画曲线,复杂些:
画的只是曲线(非弧线),在上述代码的基础上,定义几个动态储存点,捕捉鼠标的双击事件,用它来确定曲线的最终点。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询