VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   4520
   ClientLeft      =   40
   ClientTop       =   380
   ClientWidth     =   8900
   LinkTopic       =   "Form1"
   ScaleHeight     =   4520
   ScaleWidth      =   8900
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdLoad 
      Caption         =   "&Load Image"
      BeginProperty Font 
         Name            =   "Segoe UI"
         Size            =   8
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   580
      Left            =   60
      TabIndex        =   4
      Top             =   1890
      Width           =   1780
   End
   Begin VB.TextBox txtCrop 
      Alignment       =   1  'Right Justify
      BeginProperty Font 
         Name            =   "Segoe UI"
         Size            =   8
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   340
      Index           =   2
      Left            =   1020
      TabIndex        =   2
      Text            =   "0"
      Top             =   660
      Width           =   790
   End
   Begin VB.TextBox txtCrop 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "Segoe UI"
         Size            =   8
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   340
      Index           =   3
      Left            =   570
      TabIndex        =   3
      Text            =   "0"
      Top             =   1110
      Width           =   790
   End
   Begin VB.TextBox txtCrop 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "Segoe UI"
         Size            =   8
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   340
      Index           =   1
      Left            =   570
      TabIndex        =   1
      Text            =   "0"
      Top             =   210
      Width           =   790
   End
   Begin VB.TextBox txtCrop 
      BeginProperty Font 
         Name            =   "Segoe UI"
         Size            =   8
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   340
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Text            =   "0"
      Top             =   660
      Width           =   790
   End
   Begin VB.PictureBox picImage 
      Appearance      =   0  'Flat
      BackColor       =   &H80000005&
      BeginProperty Font 
         Name            =   "Segoe UI"
         Size            =   8
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000008&
      Height          =   4390
      Left            =   1920
      ScaleHeight     =   4370
      ScaleWidth      =   6920
      TabIndex        =   6
      Top             =   60
      Width           =   6940
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "&Save Cropped Image"
      BeginProperty Font 
         Name            =   "Segoe UI"
         Size            =   8
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   580
      Left            =   60
      TabIndex        =   5
      Top             =   2730
      Width           =   1780
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private WithEvents mo_Canvas As cCropCanvas
Private m_IgnoreCropRectChange As Boolean

Private Sub cmdLoad_Click()
   Dim l_File As String
   
   With New_c.FSO
      l_File = .ShowOpenDialog(OFN_EXPLORER Or OFN_FILEMUSTEXIST, .GetSpecialFolder(CSIDL_MYPICTURES), "Select an Image File", , "*.jpeg|*.jpg|*.bmp|*.png", , Me.hWnd)
      If l_File <> vbNullString Then
         mo_Canvas.LoadImage l_File
      End If
   End With
End Sub

Private Sub Form_Load()
   Set mo_Canvas = New cCropCanvas
   mo_Canvas.Initialize Me.picImage
   mo_Canvas.LoadImage App.Path & "\test.jpg"
End Sub

Private Sub cmdSave_Click()
   Dim l_File As String
   
   With New_c.FSO
      l_File = .ShowSaveDialog(OFN_EXPLORER Or OFN_OVERWRITEPROMPT Or OFN_PATHMUSTEXIST, .GetSpecialFolder(CSIDL_MYPICTURES) & "\", "Save Image", , "*.jpg|*.jpeg|*.bmp|*.png", ".jpg", Me.hWnd)
      If l_File <> vbNullString Then
         mo_Canvas.SaveImage l_File
      End If
   End With
End Sub

Private Sub Form_Resize()
   With Me.picImage
      .Move .Left, .Top, Me.ScaleWidth - .Left - .Top, Me.ScaleHeight - .Top * 2
   End With
End Sub

Private Sub mo_Canvas_CropRectChanged(ByVal p_Left As Long, ByVal p_Top As Long, ByVal p_Right As Long, ByVal p_Bottom As Long)
   m_IgnoreCropRectChange = True
   
   Me.txtCrop(0).Text = p_Left
   Me.txtCrop(1).Text = p_Top
   Me.txtCrop(2).Text = p_Right
   Me.txtCrop(3).Text = p_Bottom
   
   m_IgnoreCropRectChange = False
   
   Me.Refresh
End Sub

Private Sub txtCrop_Change(Index As Integer)
   Dim l_TestLong As Long
   
   If m_IgnoreCropRectChange Then Exit Sub
   If mo_Canvas Is Nothing Then Exit Sub
   If Not mo_Canvas.IsImageLoaded Then Exit Sub
   
   On Error Resume Next
   l_TestLong = CLng(Me.txtCrop(Index).Text)
   If Err Then Exit Sub
   On Error GoTo 0
   
   mo_Canvas.SetCropRect Me.txtCrop(0).Text, Me.txtCrop(1).Text, Me.txtCrop(2).Text, Me.txtCrop(3).Text
End Sub

Private Sub txtCrop_GotFocus(Index As Integer)
   With Me.txtCrop(Index)
      .SelStart = 0
      .SelLength = Len(.Text)
   End With
End Sub
