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 MoreAboutComponentButton As System.Windows.Forms.Button
    Friend WithEvents OrderButton As System.Windows.Forms.Button
    Friend WithEvents OpenJPEGFileDialog As System.Windows.Forms.OpenFileDialog
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents f_in_box__control1 As f_in_box__lib.f_in_box__control
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.MoreAboutComponentButton = New System.Windows.Forms.Button
        Me.OrderButton = New System.Windows.Forms.Button
        Me.OpenJPEGFileDialog = New System.Windows.Forms.OpenFileDialog
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.f_in_box__control1 = New f_in_box__lib.f_in_box__control
        Me.SuspendLayout()
        '
        'MoreAboutComponentButton
        '
        Me.MoreAboutComponentButton.Location = New System.Drawing.Point(272, 424)
        Me.MoreAboutComponentButton.Name = "MoreAboutComponentButton"
        Me.MoreAboutComponentButton.Size = New System.Drawing.Size(176, 24)
        Me.MoreAboutComponentButton.TabIndex = 3
        Me.MoreAboutComponentButton.Text = "More about F-IN-BOX"
        '
        'OrderButton
        '
        Me.OrderButton.Location = New System.Drawing.Point(456, 424)
        Me.OrderButton.Name = "OrderButton"
        Me.OrderButton.Size = New System.Drawing.Size(168, 24)
        Me.OrderButton.TabIndex = 3
        Me.OrderButton.Text = "Buy license"
        '
        'OpenJPEGFileDialog
        '
        Me.OpenJPEGFileDialog.Filter = "JPEG Files (*.jpg, *.jpeg)|*.jpg;*.jpeg|All Files (*.*)|*.*"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(616, 32)
        Me.Label1.TabIndex = 4
        Me.Label1.Text = "The movie loads each image using a relative path. The application provides conten" & _
        "t of the images. All images are loading from System.IO.Stream. Click ""Load exter" & _
        "nal image..."" to load image from external file."
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 40)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(616, 32)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "The application uses the event OnLoadExternalResourceByRelativePath. This event i" & _
        "s called when a movie tries to load an external resource (xml, jpeg, mp3, etc.) " & _
        "using a relative path. Provide a content by handling the event."
        '
        'f_in_box__control1
        '
        Me.f_in_box__control1.Context = Nothing
        Me.f_in_box__control1.FlashProperty_AlignMode = 0
        Me.f_in_box__control1.FlashProperty_AllowScriptAccess = ""
        Me.f_in_box__control1.FlashProperty_BackgroundColor = -1
        Me.f_in_box__control1.FlashProperty_Base = ""
        Me.f_in_box__control1.FlashProperty_BGColor = ""
        Me.f_in_box__control1.FlashProperty_DeviceFont = False
        Me.f_in_box__control1.FlashProperty_EmbedMovie = False
        Me.f_in_box__control1.FlashProperty_FlashVars = ""
        Me.f_in_box__control1.FlashProperty_FrameNum = -1
        Me.f_in_box__control1.FlashProperty_Loop = True
        Me.f_in_box__control1.FlashProperty_Menu = True
        Me.f_in_box__control1.FlashProperty_Movie = ""
        Me.f_in_box__control1.FlashProperty_MovieData = ""
        Me.f_in_box__control1.FlashProperty_Playing = True
        Me.f_in_box__control1.FlashProperty_Quality = 1
        Me.f_in_box__control1.FlashProperty_Quality2 = "High"
        Me.f_in_box__control1.FlashProperty_SAlign = ""
        Me.f_in_box__control1.FlashProperty_Scale = "ShowAll"
        Me.f_in_box__control1.FlashProperty_ScaleMode = 0
        Me.f_in_box__control1.FlashProperty_Stacking = ""
        Me.f_in_box__control1.FlashProperty_SWRemote = ""
        Me.f_in_box__control1.FlashProperty_WMode = "Window"
        Me.f_in_box__control1.Location = New System.Drawing.Point(8, 72)
        Me.f_in_box__control1.Name = "f_in_box__control1"
        Me.f_in_box__control1.Size = New System.Drawing.Size(616, 344)
        Me.f_in_box__control1.StandardMenu = False
        Me.f_in_box__control1.TabIndex = 5
        Me.f_in_box__control1.Text = "f_in_box__control1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(632, 462)
        Me.Controls.Add(Me.f_in_box__control1)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.MoreAboutComponentButton)
        Me.Controls.Add(Me.OrderButton)
        Me.Controls.Add(Me.Label2)
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.Text = "Sample 6 - external resources embedding"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OpenJPEGFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath())

        F_in_box__control1.PutMovieFromStream(Me.GetType().Assembly.GetManifestResourceStream("Sample06_ExternalResourcesEmbedding.load_images.swf"))
        F_in_box__control1.FlashMethod_Play()
    End Sub

    Private Sub MoreAboutComponentButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MoreAboutComponentButton.Click
        System.Diagnostics.Process.Start("http://www.f-in-box.com/dotnet/")
    End Sub

    Private Sub OrderButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrderButton.Click
        System.Diagnostics.Process.Start("http://www.f-in-box.com/dotnet/order.html")
    End Sub

    Private Sub f_in_box__control1_OnLoadExternalResourceByRelativePath(ByVal sender As Object, ByVal URL As String, ByVal Stream As System.IO.Stream, ByRef Handled As Boolean) Handles f_in_box__control1.OnLoadExternalResourceByRelativePath

        Dim FromStream As System.IO.Stream = Nothing

        If URL = "images/embedded_image1.jpg" Then
            FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample06_ExternalResourcesEmbedding.embedded_image1.jpg")
        End If

        If URL = "images/embedded_image2.jpg" Then
            FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample06_ExternalResourcesEmbedding.embedded_image2.jpg")
        End If

        If URL = "images/embedded_image3.jpg" Then
            FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample06_ExternalResourcesEmbedding.embedded_image3.jpg")
        End If

        If URL = "images/embedded_image4.jpg" Then
            FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample06_ExternalResourcesEmbedding.embedded_image4.jpg")
        End If

        If URL = "images/embedded_image5.jpg" Then
            FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample06_ExternalResourcesEmbedding.embedded_image5.jpg")
        End If

        If URL = "images/external_image.jpg" Then
            If OpenJPEGFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                FromStream = OpenJPEGFileDialog.OpenFile()
            End If
        End If

        If Not FromStream Is Nothing Then

            ' Also you can write content in a separate thread

            Const Size As Integer = 64 * 1024
            Dim buffer(Size) As Byte
            Dim ReadBytes As Integer

            While True

                ReadBytes = FromStream.Read(buffer, 0, Size)

                If ReadBytes = 0 Then Exit While

                Try
                    Stream.Write(buffer, 0, ReadBytes)
                Catch e As System.IO.IOException
                    ' Loading is interrupted
                    Exit While
                End Try

            End While

            Stream.Close()

            Handled = True

        End If

    End Sub
End Class
