Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
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 ImageKit1 As AxIMAGEKIT7Lib.AxImageKit
	Public WithEvents Text1 As System.Windows.Forms.TextBox
	'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.ImageKit1 = New AxIMAGEKIT7Lib.AxImageKit
        Me.Text1 = New System.Windows.Forms.TextBox
        CType(Me.ImageKit1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'ImageKit1
        '
        Me.ImageKit1.Location = New System.Drawing.Point(8, 56)
        Me.ImageKit1.Name = "ImageKit1"
        Me.ImageKit1.OcxState = CType(resources.GetObject("ImageKit1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.ImageKit1.Size = New System.Drawing.Size(513, 385)
        Me.ImageKit1.TabIndex = 1
        '
        '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.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        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(64, Byte), CType(0, Byte))
        Me.Text1.Location = New System.Drawing.Point(0, 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(521, 49)
        Me.Text1.TabIndex = 0
        Me.Text1.Text = "Not only can we display multiple images simultaneously and set their positions, b" & _
        "y using the MouseDownSelectLayerImage event in conjunction with the MouseMoveIma" & _
        "ge and MouseUpImage events we can use the mouse to select an image layer and rep" & _
        "osition it by simply dragging it where we want it."
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(528, 453)
        Me.Controls.Add(Me.ImageKit1)
        Me.Controls.Add(Me.Text1)
        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, 30)
        Me.Name = "Form1"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Text = "Moving Image Layers With Mouse"
        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 
	Dim LayerNo As Integer
	Dim RasterImageOffsetX(6) As Integer
	Dim RasterImageOffsetY(6) As Integer
	Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim n As Short
		
		ImageKit1.ImageHandle = 0
		For n = 0 To 6
			ImageKit1.get_Layer(n).ImageHandle = 0
			
			RasterImageOffsetX(n) = 0
			RasterImageOffsetY(n) = 0
		Next n
		LoadRasterImage()
	End Sub
	
	Private Sub LoadRasterImage()
		Dim n As Integer
		LayerNo = -1
        ImageKit1.File.FileName = Application.StartupPath & "\..\..\..\..\..\..\Images\ForSamples\base.jpg"
		ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad)
		
		For n = 0 To 6
			ImageKit1.LayerNo = n
            ImageKit1.File.FileName = Application.StartupPath & "\..\..\..\..\..\..\Images\ForSamples\" & VB.Right(Str(n), 1) & ".bmp"
			ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad)
			
			'ImageKit1.Layer(n).Transparent = False
			
			ImageKit1.get_Layer(n).TransRed = 0
			ImageKit1.get_Layer(n).TransGreen = 0
			ImageKit1.get_Layer(n).TransBlue = 0
			
			ImageKit1.get_Layer(n).ImageHandle = ImageKit1.CopyImage(0)
			
			ImageKit1.get_Layer(n).StartX = n * 90
			ImageKit1.get_Layer(n).StartY = n * 65
		Next n
		
		ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale)
	End Sub


    Private Sub ImageKit1_MouseUpImage(ByVal sender As Object, ByVal e As AxIMAGEKIT7Lib._IImageKitEvents_MouseUpImageEvent) Handles ImageKit1.MouseUpImage
        LayerNo = -1
    End Sub

    Private Sub ImageKit1_MouseMoveImage(ByVal sender As Object, ByVal e As AxIMAGEKIT7Lib._IImageKitEvents_MouseMoveImageEvent) Handles ImageKit1.MouseMoveImage
        If LayerNo < 0 Then Exit Sub

        ImageKit1.get_Layer(LayerNo).StartX = 0 + e.x - RasterImageOffsetX(LayerNo)
        ImageKit1.get_Layer(LayerNo).StartY = 0 + e.y - RasterImageOffsetY(LayerNo)
        ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale)
    End Sub

    Private Sub ImageKit1_MouseDownSelectLayerImage(ByVal sender As Object, ByVal e As AxIMAGEKIT7Lib._IImageKitEvents_MouseDownSelectLayerImageEvent) Handles ImageKit1.MouseDownSelectLayerImage
        If e.index < 0 Then Exit Sub
        LayerNo = e.index
        RasterImageOffsetX(LayerNo) = e.x
        RasterImageOffsetY(LayerNo) = e.y
    End Sub
End Class