Option Strict Off
Option Explicit On
Friend Class Form1
	Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
	Public Sub New()
		MyBase.New()
		If m_vb6FormDefInstance Is Nothing Then
			If m_InitializingDefInstance Then
				m_vb6FormDefInstance = Me
			Else
				Try 
					'For the start-up form, the first instance created is the default instance.
					If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
						m_vb6FormDefInstance = Me
					End If
				Catch
				End Try
			End If
		End If
		'This call is required by the Windows Form Designer.
		InitializeComponent()
	End Sub
	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
		If Disposing Then
			If Not components Is Nothing Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(Disposing)
	End Sub
	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer
    Public WithEvents Text1 As System.Windows.Forms.TextBox
	Public WithEvents Command5 As System.Windows.Forms.Button
	Public WithEvents ImageKit1 As AxIMAGEKIT7Lib.AxImageKit
	Public WithEvents Command4 As System.Windows.Forms.Button
	Public WithEvents Command3 As System.Windows.Forms.Button
	Public WithEvents Command2 As System.Windows.Forms.Button
	Public WithEvents Command1 As System.Windows.Forms.Button
	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.
	'Do not modify it using the code editor.
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Text1 = New System.Windows.Forms.TextBox
        Me.Command5 = New System.Windows.Forms.Button
        Me.ImageKit1 = New AxIMAGEKIT7Lib.AxImageKit
        Me.Command4 = New System.Windows.Forms.Button
        Me.Command3 = New System.Windows.Forms.Button
        Me.Command2 = New System.Windows.Forms.Button
        Me.Command1 = New System.Windows.Forms.Button
        CType(Me.ImageKit1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'Text1
        '
        Me.Text1.AcceptsReturn = True
        Me.Text1.AutoSize = False
        Me.Text1.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(255, Byte), CType(192, Byte))
        Me.Text1.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.Text1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Text1.ForeColor = System.Drawing.Color.FromArgb(CType(192, Byte), CType(0, Byte), CType(0, Byte))
        Me.Text1.Location = New System.Drawing.Point(8, 0)
        Me.Text1.MaxLength = 0
        Me.Text1.Multiline = True
        Me.Text1.Name = "Text1"
        Me.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Text1.Size = New System.Drawing.Size(553, 65)
        Me.Text1.TabIndex = 6
        Me.Text1.Text = "After you have edited an image, you must transfer the modifications to the ImageH" & _
        "andle before they can be saved. The Edit interface (Image-Editing Toolbars) writ" & _
        "es modifications to the ImageHdc. To transfer that to the ImageHandle, you need " & _
        "to call the Modify method. The PrintDraw interface allows you to write directly " & _
        "to the ImageHandle or to use the ImageHdc and the Modify method combination."
        '
        'Command5
        '
        Me.Command5.BackColor = System.Drawing.SystemColors.Control
        Me.Command5.Cursor = System.Windows.Forms.Cursors.Default
        Me.Command5.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Command5.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Command5.Location = New System.Drawing.Point(448, 400)
        Me.Command5.Name = "Command5"
        Me.Command5.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command5.Size = New System.Drawing.Size(113, 41)
        Me.Command5.TabIndex = 5
        Me.Command5.Text = "End"
        '
        'ImageKit1
        '
        Me.ImageKit1.Location = New System.Drawing.Point(8, 72)
        Me.ImageKit1.Name = "ImageKit1"
        Me.ImageKit1.OcxState = CType(resources.GetObject("ImageKit1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.ImageKit1.Size = New System.Drawing.Size(433, 369)
        Me.ImageKit1.TabIndex = 4
        '
        'Command4
        '
        Me.Command4.BackColor = System.Drawing.SystemColors.Control
        Me.Command4.Cursor = System.Windows.Forms.Cursors.Default
        Me.Command4.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Command4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Command4.Location = New System.Drawing.Point(448, 344)
        Me.Command4.Name = "Command4"
        Me.Command4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command4.Size = New System.Drawing.Size(113, 41)
        Me.Command4.TabIndex = 3
        Me.Command4.Text = "Save Image"
        '
        'Command3
        '
        Me.Command3.BackColor = System.Drawing.SystemColors.Control
        Me.Command3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Command3.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Command3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Command3.Location = New System.Drawing.Point(448, 224)
        Me.Command3.Name = "Command3"
        Me.Command3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command3.Size = New System.Drawing.Size(113, 57)
        Me.Command3.TabIndex = 2
        Me.Command3.Text = "Draw Red Line To ImageHdc And Call Modify Method"
        '
        'Command2
        '
        Me.Command2.BackColor = System.Drawing.SystemColors.Control
        Me.Command2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Command2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Command2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Command2.Location = New System.Drawing.Point(448, 152)
        Me.Command2.Name = "Command2"
        Me.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command2.Size = New System.Drawing.Size(113, 57)
        Me.Command2.TabIndex = 1
        Me.Command2.Text = "Draw Blue Line To Image Handle"
        '
        'Command1
        '
        Me.Command1.BackColor = System.Drawing.SystemColors.Control
        Me.Command1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Command1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Command1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Command1.Location = New System.Drawing.Point(448, 72)
        Me.Command1.Name = "Command1"
        Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command1.Size = New System.Drawing.Size(113, 41)
        Me.Command1.TabIndex = 0
        Me.Command1.Text = "Load Image"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(566, 449)
        Me.Controls.Add(Me.Text1)
        Me.Controls.Add(Me.Command5)
        Me.Controls.Add(Me.ImageKit1)
        Me.Controls.Add(Me.Command4)
        Me.Controls.Add(Me.Command3)
        Me.Controls.Add(Me.Command2)
        Me.Controls.Add(Me.Command1)
        Me.Cursor = System.Windows.Forms.Cursors.Default
        Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Location = New System.Drawing.Point(4, 23)
        Me.Name = "Form1"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Text = "Saving Image Modifications"
        CType(Me.ImageKit1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
#End Region 
#Region "Upgrade Support "
	Private Shared m_vb6FormDefInstance As Form1
	Private Shared m_InitializingDefInstance As Boolean
	Public Shared Property DefInstance() As Form1
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New Form1()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property
#End Region 
	'Loads and displays an image in the ImageKit Control
	Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
		'displays the 'Open File' dialog and allows you to select an image to load...
		If ImageKit1.File.OpenFileDialog = False Then
			Exit Sub
		End If
		
		'loads the image...
		ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad)
		
		'displays the image in scale display mode...
		ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale)
		
	End Sub

	Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
		Dim ret As Short
		
		'reset the PrintDraw interface's property values...
		ImageKit1.PrintDraw.ClearProperty()
		
		'set some properties necessary for the Line method...
		ImageKit1.PrintDraw.PenColor = RGB(0, 0, 255)
		ImageKit1.PrintDraw.PenWidth = 10
		ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid
		
		'execute the Line method, drawing the line to the ImageHandle
		ret = ImageKit1.PrintDraw.Line(ImageKit1.ImageHandle, 10, 150, 150, 10, IMAGEKIT7Lib.OutPutDeviceModeConstants.ikMemoryHandle)
		'redisplay the image so the the text will appear on the screen...
		ImageKit1.CtlRefresh()
		
	End Sub
	
	'Draws a line on the image
	Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click
        Dim ret As Boolean
		
		'enable editing...
		ImageKit1.Edit.EditEnable = True
		
		'set some properties necessary for the Line method...
		ImageKit1.PrintDraw.PenColor = RGB(255, 0, 0)
		ImageKit1.PrintDraw.PenWidth = 10
		ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid
		
		'execute the Line method, drawing the line to the ImageHdc
		' Note: because the DeviceMode parameter is set to ikScreen,
		'       the line is drawn in pixels...
		ret = ImageKit1.PrintDraw.Line(ImageKit1.ImageHdc, 10, 10, 150, 150, IMAGEKIT7Lib.OutPutDeviceModeConstants.ikScreen)
		
		'execute the Modify method to transfer the data from the ImageHdc to the ImageHandle...
		ImageKit1.Edit.Modify()
		
		'redisplay the image so the the text will appear on the screen...
		ImageKit1.CtlRefresh()
		
		'turn off editing
		ImageKit1.Edit.EditEnable = False
	End Sub
	'save the image
	Private Sub Command4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click
		
		'exit if there is no image loaded...
		If ImageKit1.ImageHandle = 0 Then
			Exit Sub
		End If
		
		'set the file extensions that are displayed in the "Save" file dialog.
		ImageKit1.File.FileExt = "*;BMP;JPG;GIF;"
		
		'display the "Save" file dialog...
		If ImageKit1.File.SaveFileDialog = False Then
			Exit Sub
		End If
		
		'use the value of the SaveFileDlgFileType to determine the SaveFile method...
		Select Case ImageKit1.File.SaveFileDlgFileType
			
			Case 1
				'save as uncompressed bmp...
				ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveBMP, 0)
				
			Case 2
				'save as jpeg. Must check the bitcount and don't forget the JpegQuality!
				If ImageKit1.BitCount = 24 Then
					ImageKit1.File.JpegQuality = 70
					ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveJPEG, 0)
				ElseIf ImageKit1.BitCount = 8 And ImageKit1.Gray <> False Then 
					ImageKit1.File.JpegQuality = 70
					ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveJPEG, 0)
				Else
					MsgBox("Jpeg images must be 24 bit color or 8 bit grayscale")
					Exit Sub
				End If
				
			Case 3
				'save as gif. Must check the bitcount!
				If ImageKit1.BitCount > 8 Then
					MsgBox("Gif images must be 256 colors or less")
					Exit Sub
				End If
				ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveGIF, 0)
			Case Else ' do not save
				MsgBox("Unable to save the image")
		End Select
		
	End Sub
	
	Private Sub Command5_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command5.Click
		Me.Close()
	End Sub
End Class