比如说我先画好直线,再画矩形
之前画的直线就没有了
怎么改能让之前画的都留在画板上呢?谢谢~~以下是代码
Dim color1 As Long
Dim a, b As Integer
Dim xx, yy As IntegerPrivate Sub Toolbar1_ButtonClick(ByVal Button As MSComCtlLib.Button)
On Error Resume Next
Select Case Button.Key
Case "直线"
Call line_Click
a = 0
Case "椭圆"
Call cycle_Click
a = 1
Case "矩形"
Call rec_Click
a = 2
Case "保存"
Call save_Click
Case "打开"
Call open_Click
Case "新建"
Call build_Click
End Select
End SubPrivate Sub build_Click()
Set Picture1.Picture = Nothing
save1 = 0
Picture1.Top = 480
Picture1.Left = 1080
Picture1.Height = 3735
Picture1.Width = 6255
End SubPrivate Sub command1_Click()
color1 = Command1.BackColor
b = 0
End SubPrivate Sub Command2_Click()
color1 = Command2.BackColor
b = 1
End SubPrivate Sub Command3_Click()
color1 = Command3.BackColor
b = 2
End SubPrivate Sub Command4_Click()
color1 = Command4.BackColor
b = 3
End SubPrivate Sub Command5_Click()
color1 = Command5.BackColor
b = 4
End SubPrivate Sub cycle_Click()
a = 1
End SubPrivate Sub end_Click()
End
End SubPrivate Sub help_Click()
MsgBox "画图程序!"
End SubPrivate Sub Form_Load()
Command1.Value = True
End SubPrivate Sub line_Click()
a = 0
End SubPrivate Sub open_Click()
On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.Filter = "图像文件(*.Bmp;*.jpg;*.ico;*.gif)|*.Bmp;*.jpg;*.ico;*.gif"
CommonDialog1.Flags = &H200000
CommonDialog1.ShowOpen
If Err.Number <> 32755 Then
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
End If
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If k > 100 Then
k = 0
End If
Select Case a
Case 0
Picture1.Height = Picture1.Height
Picture1.Width = Picture1.Width
Picture1.Picture = Picture1.Image
xx = X
yy = Y
Case 1
Picture1.Height = Picture1.Height
Picture1.Width = Picture1.Width
Picture1.Picture = Picture1.Image
xx = X
yy = Y
Case 2
Picture1.Height = Picture1.Height
Picture1.Width = Picture1.Width
Picture1.Picture = Picture1.Image
xx = X
yy = Y
End Select
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Select Case a
Case 0
Picture1.Cls
Picture1.Picture = Picture1.Image
Picture1.Line (xx, yy)-(X, Y), color1
Case 1
Picture1.Cls
Picture1.Picture = Picture1.Image
Picture1.Circle (xx, yy), Sqr((X - xx) * (X - xx) + (Y - yy) * (Y - yy)), color1, , , Y / X
Case 2
Picture1.Cls
Picture1.Picture = Picture1.Image
Picture1.Line (xx, yy)-(X, Y), color1, B
End Select
End If
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Select Case a
Case 0
Picture1.Picture = Picture1.Image
Picture1.Line (xx, yy)-(X, Y), color1
Case 1
Picture1.Picture = Picture1.Image
Picture1.Circle (xx, yy), Sqr((X - xx) * (X - xx) + (Y - yy) * (Y - yy)), color1, , , Y / X
Case 2
Picture1.Picture = Picture1.Image
Picture1.Line (xx, yy)-(X, Y), color1, B
End Select
End If
End SubPrivate Sub rec_Click()
a = 2
End SubPrivate Sub save_Click()
On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.Filter = "Bmp图像文件(*.Bmp)|*.Bmp|所有文件(*.*)|*.*"
CommonDialog1.Flags = &H200000
CommonDialog1.ShowSave
If Err.Number <> 32755 Then
SavePicture Picture1.Image, CommonDialog1.FileName
End If
End SubPrivate Sub selcol_Click()
On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.Flags = &H1 Or &H2
CommonDialog1.ShowColor
If Err.Number <> 32755 Then
Select Case b
Case 0: Command1.BackColor = CommonDialog1.color
Case 1: Command2.BackColor = CommonDialog1.color
Case 2: Command3.BackColor = CommonDialog1.color
Case 3: Command4.BackColor = CommonDialog1.color
Case 4: Command5.BackColor = CommonDialog1.color
End Select
color1 = CommonDialog1.color
End If
End Sub
之前画的直线就没有了
怎么改能让之前画的都留在画板上呢?谢谢~~以下是代码
Dim color1 As Long
Dim a, b As Integer
Dim xx, yy As IntegerPrivate Sub Toolbar1_ButtonClick(ByVal Button As MSComCtlLib.Button)
On Error Resume Next
Select Case Button.Key
Case "直线"
Call line_Click
a = 0
Case "椭圆"
Call cycle_Click
a = 1
Case "矩形"
Call rec_Click
a = 2
Case "保存"
Call save_Click
Case "打开"
Call open_Click
Case "新建"
Call build_Click
End Select
End SubPrivate Sub build_Click()
Set Picture1.Picture = Nothing
save1 = 0
Picture1.Top = 480
Picture1.Left = 1080
Picture1.Height = 3735
Picture1.Width = 6255
End SubPrivate Sub command1_Click()
color1 = Command1.BackColor
b = 0
End SubPrivate Sub Command2_Click()
color1 = Command2.BackColor
b = 1
End SubPrivate Sub Command3_Click()
color1 = Command3.BackColor
b = 2
End SubPrivate Sub Command4_Click()
color1 = Command4.BackColor
b = 3
End SubPrivate Sub Command5_Click()
color1 = Command5.BackColor
b = 4
End SubPrivate Sub cycle_Click()
a = 1
End SubPrivate Sub end_Click()
End
End SubPrivate Sub help_Click()
MsgBox "画图程序!"
End SubPrivate Sub Form_Load()
Command1.Value = True
End SubPrivate Sub line_Click()
a = 0
End SubPrivate Sub open_Click()
On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.Filter = "图像文件(*.Bmp;*.jpg;*.ico;*.gif)|*.Bmp;*.jpg;*.ico;*.gif"
CommonDialog1.Flags = &H200000
CommonDialog1.ShowOpen
If Err.Number <> 32755 Then
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
End If
End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If k > 100 Then
k = 0
End If
Select Case a
Case 0
Picture1.Height = Picture1.Height
Picture1.Width = Picture1.Width
Picture1.Picture = Picture1.Image
xx = X
yy = Y
Case 1
Picture1.Height = Picture1.Height
Picture1.Width = Picture1.Width
Picture1.Picture = Picture1.Image
xx = X
yy = Y
Case 2
Picture1.Height = Picture1.Height
Picture1.Width = Picture1.Width
Picture1.Picture = Picture1.Image
xx = X
yy = Y
End Select
End If
End SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Select Case a
Case 0
Picture1.Cls
Picture1.Picture = Picture1.Image
Picture1.Line (xx, yy)-(X, Y), color1
Case 1
Picture1.Cls
Picture1.Picture = Picture1.Image
Picture1.Circle (xx, yy), Sqr((X - xx) * (X - xx) + (Y - yy) * (Y - yy)), color1, , , Y / X
Case 2
Picture1.Cls
Picture1.Picture = Picture1.Image
Picture1.Line (xx, yy)-(X, Y), color1, B
End Select
End If
End SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Select Case a
Case 0
Picture1.Picture = Picture1.Image
Picture1.Line (xx, yy)-(X, Y), color1
Case 1
Picture1.Picture = Picture1.Image
Picture1.Circle (xx, yy), Sqr((X - xx) * (X - xx) + (Y - yy) * (Y - yy)), color1, , , Y / X
Case 2
Picture1.Picture = Picture1.Image
Picture1.Line (xx, yy)-(X, Y), color1, B
End Select
End If
End SubPrivate Sub rec_Click()
a = 2
End SubPrivate Sub save_Click()
On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.Filter = "Bmp图像文件(*.Bmp)|*.Bmp|所有文件(*.*)|*.*"
CommonDialog1.Flags = &H200000
CommonDialog1.ShowSave
If Err.Number <> 32755 Then
SavePicture Picture1.Image, CommonDialog1.FileName
End If
End SubPrivate Sub selcol_Click()
On Error Resume Next
CommonDialog1.CancelError = True
CommonDialog1.Flags = &H1 Or &H2
CommonDialog1.ShowColor
If Err.Number <> 32755 Then
Select Case b
Case 0: Command1.BackColor = CommonDialog1.color
Case 1: Command2.BackColor = CommonDialog1.color
Case 2: Command3.BackColor = CommonDialog1.color
Case 3: Command4.BackColor = CommonDialog1.color
Case 4: Command5.BackColor = CommonDialog1.color
End Select
color1 = CommonDialog1.color
End If
End Sub
为什么还要在保存的时候执行set picture1.picture = picture1.image?
=====================
Image 属性
返回持久图形的句柄,该句柄由 Microsoft Windows 运行环境提供。语法object.Imageobject 所在处代表一个对象表达式,其值是“应用于”列表中的一个对象。说明对象的 AutoRedraw 属性决定是否用持久图形或通过 Paint 事件重绘对象。 Windows 运行环境通过给对象的持久图形分配一个句柄来标识它;用 Image 属性可以得到该句柄。 Image 值的存在,不受 AutoRedraw 属性设置值的影响。如果 AutoRedraw 为 True,并且还没有绘任何内容,图象仅显示由 BackColor 属性和图片确定的颜色。可以给 Picture 属性分配 Image 的值。Image 属性还提供了一个传递给 Windows API调用的值。 Image、DragIcon 和 Picture 属性,通常用在给其它属性分配值的情况,如用 SavePicture 语句保存,或在剪贴板上放置一些内容。除图象数据类型外,不能把它们赋给临时变量。AutoRedraw 属性可以引起 Image 改变,Image 是指向位图的句柄。当 AutoRedraw 为 True 时,对象的 hDC 属性成为指向设备描述体的句柄,该设备描述体包含 Image 返回的位图。