Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    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

    '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.
    Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents radioButton3 As System.Windows.Forms.RadioButton
    Friend WithEvents radioButton2 As System.Windows.Forms.RadioButton
    Friend WithEvents radioButton1 As System.Windows.Forms.RadioButton
    Public WithEvents Command2 As System.Windows.Forms.Button
    Public WithEvents Command1 As System.Windows.Forms.Button
    Public WithEvents Text1 As System.Windows.Forms.TextBox
    Friend WithEvents ImageKit1 As AxIMAGEKIT7Lib.AxImageKit
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.groupBox1 = New System.Windows.Forms.GroupBox
        Me.radioButton3 = New System.Windows.Forms.RadioButton
        Me.radioButton2 = New System.Windows.Forms.RadioButton
        Me.radioButton1 = New System.Windows.Forms.RadioButton
        Me.Command2 = New System.Windows.Forms.Button
        Me.Command1 = New System.Windows.Forms.Button
        Me.Text1 = New System.Windows.Forms.TextBox
        Me.ImageKit1 = New AxIMAGEKIT7Lib.AxImageKit
        Me.groupBox1.SuspendLayout()
        CType(Me.ImageKit1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'groupBox1
        '
        Me.groupBox1.Controls.Add(Me.radioButton3)
        Me.groupBox1.Controls.Add(Me.radioButton2)
        Me.groupBox1.Controls.Add(Me.radioButton1)
        Me.groupBox1.Location = New System.Drawing.Point(384, 72)
        Me.groupBox1.Name = "groupBox1"
        Me.groupBox1.Size = New System.Drawing.Size(112, 80)
        Me.groupBox1.TabIndex = 14
        Me.groupBox1.TabStop = False
        Me.groupBox1.Text = "Database Images"
        '
        'radioButton3
        '
        Me.radioButton3.Location = New System.Drawing.Point(16, 56)
        Me.radioButton3.Name = "radioButton3"
        Me.radioButton3.Size = New System.Drawing.Size(80, 16)
        Me.radioButton3.TabIndex = 2
        Me.radioButton3.Text = "Image 3"
        '
        'radioButton2
        '
        Me.radioButton2.Location = New System.Drawing.Point(16, 40)
        Me.radioButton2.Name = "radioButton2"
        Me.radioButton2.Size = New System.Drawing.Size(80, 16)
        Me.radioButton2.TabIndex = 1
        Me.radioButton2.Text = "Image 2"
        '
        'radioButton1
        '
        Me.radioButton1.Location = New System.Drawing.Point(16, 24)
        Me.radioButton1.Name = "radioButton1"
        Me.radioButton1.Size = New System.Drawing.Size(80, 16)
        Me.radioButton1.TabIndex = 0
        Me.radioButton1.Text = "Image 1"
        '
        '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(384, 288)
        Me.Command2.Name = "Command2"
        Me.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command2.Size = New System.Drawing.Size(112, 41)
        Me.Command2.TabIndex = 13
        Me.Command2.Text = "End"
        '
        '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(384, 168)
        Me.Command1.Name = "Command1"
        Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Command1.Size = New System.Drawing.Size(112, 41)
        Me.Command1.TabIndex = 12
        Me.Command1.Text = "Retrieve image from database"
        '
        '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(488, 49)
        Me.Text1.TabIndex = 11
        Me.Text1.Text = "BLOB image data can be streamed from the database to the ImageKit. It is then con" & _
        "verted to DIB data and displayed in the ImageKit Control. This sample has a smal" & _
        "l MDB database included which contains three images." & Microsoft.VisualBasic.ChrW(13) & Microsoft.VisualBasic.ChrW(10)
        '
        '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(369, 273)
        Me.ImageKit1.TabIndex = 15
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(504, 336)
        Me.Controls.Add(Me.ImageKit1)
        Me.Controls.Add(Me.groupBox1)
        Me.Controls.Add(Me.Command2)
        Me.Controls.Add(Me.Command1)
        Me.Controls.Add(Me.Text1)
        Me.Name = "Form1"
        Me.Text = "Loading Images From Database"
        Me.groupBox1.ResumeLayout(False)
        CType(Me.ImageKit1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim ImageID As String

    Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command1.Click
        Dim ret As Boolean
        Dim cmdStatement As String
        Dim connString As String
        Dim oleDbConnection1 As OleDb.OleDbConnection
        Dim img As Byte()

        connString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Application.StartupPath + "\..\ImageDataBlob.mdb;"
        oleDbConnection1 = New OleDb.OleDbConnection(connString)

        'build a Select Statement...			
        cmdStatement = "select ImageData from Files where ID='" + ImageID + "'"
        Dim cmdSelect As OleDb.OleDbCommand = New OleDb.OleDbCommand(cmdStatement, oleDbConnection1)

        'open database connection...
        oleDbConnection1.Open()
        'retrieve image data in a byte array...
        img = cmdSelect.ExecuteScalar()
        'close database connection
        oleDbConnection1.Close()

        'load byte array (raw image data) into the ImageKit
        ImageKit1.File.LoadFromStream(img) 'Get the BLOB data from the stream

        ' convert raw date to dib data and display...
        ret = ImageKit1.File.LoadFileMem(IMAGEKIT7Lib.LoadFileConstants.ikLoad) 'Load the data as DIB into the ImageKit Control
        ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale) 'Display the image
    End Sub

    Private Sub radioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioButton1.CheckedChanged
        ImageID = "001"
    End Sub

    Private Sub radioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioButton2.CheckedChanged
        ImageID = "002"
    End Sub

    Private Sub radioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioButton3.CheckedChanged
        ImageID = "003"
    End Sub

    Private Sub Command2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command2.Click
        Me.Close()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        radioButton1.Checked = True
    End Sub
End Class
