VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "绘图程序"
   ClientHeight    =   3315
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   4710
   LinkTopic       =   "Form1"
   ScaleHeight     =   3315
   ScaleWidth      =   4710
   StartUpPosition =   3  '窗口缺省
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   2115
      Top             =   1410
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.PictureBox Picture1 
      BackColor       =   &H00FFFFFF&
      Height          =   2850
      Left            =   60
      ScaleHeight     =   2790
      ScaleWidth      =   4500
      TabIndex        =   0
      Top             =   105
      Width           =   4560
   End
   Begin VB.Menu File 
      Caption         =   "文件(&F)"
      Begin VB.Menu FileNew 
         Caption         =   "新建"
         Shortcut        =   ^N
      End
      Begin VB.Menu FileOpen 
         Caption         =   "打开"
         Shortcut        =   ^O
      End
      Begin VB.Menu FileSave 
         Caption         =   "保存"
         Shortcut        =   ^S
      End
      Begin VB.Menu a 
         Caption         =   "-"
      End
      Begin VB.Menu Exit 
         Caption         =   "退出"
         Shortcut        =   ^Q
      End
   End
   Begin VB.Menu DRAW 
      Caption         =   "绘图(&D)"
      Begin VB.Menu ELLIPSE 
         Caption         =   "椭圆"
         Begin VB.Menu DRAW_ELLIPSE1 
            Caption         =   "100*100"
         End
         Begin VB.Menu DRAW_ELLIPSE2 
            Caption         =   "100*200"
         End
         Begin VB.Menu DRAW_ELLIPSE3 
            Caption         =   "200*100"
         End
      End
      Begin VB.Menu RECT 
         Caption         =   "矩形"
         Begin VB.Menu DRAW_RECT1 
            Caption         =   "100*100"
         End
         Begin VB.Menu DRAW_RECT2 
            Caption         =   "100*200"
         End
         Begin VB.Menu DRAW_RECT3 
            Caption         =   "200*100"
         End
      End
      Begin VB.Menu DRAW_CLEAR 
         Caption         =   "清除"
         Shortcut        =   ^D
      End
   End
   Begin VB.Menu COLOR 
      Caption         =   "颜色(&C)"
      Begin VB.Menu CLR_RED 
         Caption         =   "红"
         Shortcut        =   ^R
      End
      Begin VB.Menu CLR_GREEN 
         Caption         =   "绿"
         Shortcut        =   ^G
      End
      Begin VB.Menu CLR_BLUE 
         Caption         =   "蓝"
         Shortcut        =   ^B
      End
      Begin VB.Menu CLR_MORE 
         Caption         =   "更多…"
         Shortcut        =   ^M
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Shape As Integer        '图形类型
Dim blChange As Boolean     '图片是否改变

Private Sub CLR_BLUE_Click()
    Picture1.ForeColor = RGB(0, 0, 255)  '设置绘图前景色
End Sub

Private Sub CLR_GREEN_Click()
    Picture1.ForeColor = RGB(0, 255, 0)
End Sub

Private Sub CLR_MORE_Click()
    CommonDialog1.ShowColor     '通过颜色对话框设置绘图前景色
    Picture1.ForeColor = CommonDialog1.COLOR
End Sub

Private Sub CLR_RED_Click()
    Picture1.ForeColor = RGB(255, 0, 0)
End Sub

Private Sub DRAW_CLEAR_Click()
    Picture1.Cls            '清除图片框所绘的内容
End Sub

Private Sub DRAW_ELLIPSE1_Click()
    Shape = 11
End Sub

Private Sub DRAW_ELLIPSE2_Click()
    Shape = 12
End Sub

Private Sub DRAW_ELLIPSE3_Click()
    Shape = 13
End Sub

Private Sub DRAW_RECT1_Click()
    Shape = 21
End Sub

Private Sub DRAW_RECT2_Click()
    Shape = 22
End Sub

Private Sub DRAW_RECT3_Click()
    Shape = 23
End Sub

Private Sub Exit_Click()
    End
End Sub

Private Sub FileNew_Click()
    If blChange = True Then
        If MsgBox("图片内容已改变，是否要保存当前图片？", vbYesNo) = vbYes Then
            CommonDialog1.ShowSave
            SavePicture Picture1.Image, CommonDialog1.FileName  '保存图片框内容
        End If
    End If
    Picture1.Picture = LoadPicture("")  '清空图片框内容
End Sub

Private Sub FileOpen_Click()
    CommonDialog1.ShowOpen
    Picture1.Picture = LoadPicture(CommonDialog1.FileName)  '载入图片文件
End Sub

Private Sub FileSave_Click()
    CommonDialog1.ShowSave
    SavePicture Picture1.Image, CommonDialog1.FileName  '保存图片框内容
    blChange = False
End Sub

Private Sub Form_Load()
    Picture1.ScaleMode = vbPixels       '设置度量单位为像素
    Picture1.DrawWidth = 3              '设置线宽
    Picture1.AutoRedraw = True          '设置自动重绘有效，以便保存图片
    CommonDialog1.Filter = "BMP位图|*.bmp|全部文件|*.*" '设置［打开］对话框文件过滤
    blChange = False
End Sub



Private Sub Form_Resize()
    '在窗体大小改变后，图片框自动调整大小
    Picture1.Top = 200
    Picture1.Left = 100
    Picture1.Height = Me.Height - 1000
    Picture1.Width = Me.Width - 300
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then Me.PopupMenu DRAW    '鼠标右键按下时弹出菜单
    
    Select Case Shape
    Case 11
        Picture1.Circle (X, Y), 50      '绘制圆形
    Case 12
        Picture1.Circle (X, Y), 100, , , , 0.5
    Case 13
        Picture1.Circle (X, Y), 50, , , , 2
    Case 21
        Picture1.Line (X, Y)-(X + 100, Y + 100), , B '绘制矩形
    Case 22
        Picture1.Line (X, Y)-(X + 200, Y + 100), , B
    Case 23
        Picture1.Line (X, Y)-(X + 100, Y + 200), , B
    End Select
    blChange = True
End Sub
