F-IN-BOX .NET Help >> Classes >> f_in_box__control and f_in_box__form >> Events >> Extensions

OnLoadExternalResourceByRelativePath

Syntax

[ C# ]
  1. public delegate void OnLoadExternalResourceByRelativePathEventHandler(object sender, String RelativePath, Stream ContentStream, ref bool Handled);  
  2. public event OnLoadExternalResourceByRelativePathEventHandler OnLoadExternalResourceByRelativePath;  

Description

OnLoadExternalResourceByRelativePath is called when a movie tries to load a resource using a relative path:

[ C# ]
  1. private void OnLoadExternalResourceByRelativePath(object sender, String strRelativePath, System.IO.Stream Stream, ref bool Handled)  
  2. {  
  3.     System.IO.Stream FromStream = null;  
  4.   
  5.     if (strRelativePath == "images/embedded_image1.jpg")  
  6.         FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image1.jpg");  
  7.     if (strRelativePath == "images/embedded_image2.jpg")  
  8.         FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image2.jpg");  
  9.     if (strRelativePath == "images/embedded_image3.jpg")  
  10.         FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image3.jpg");  
  11.     if (strRelativePath == "images/embedded_image4.jpg")  
  12.         FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image4.jpg");  
  13.     if (strRelativePath == "images/embedded_image5.jpg")  
  14.         FromStream = this.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.Resources.embedded_images.embedded_image5.jpg");  
  15.     if (strRelativePath == "images/external_image.jpg")  
  16.     {  
  17.         if (OpenJPEGFileDialog.ShowDialog() == DialogResult.OK)  
  18.             FromStream = OpenJPEGFileDialog.OpenFile();  
  19.     }  
  20.   
  21.     if (FromStream != null)  
  22.     {  
  23.         const int size = 64 * 1024;  
  24.         byte[] buffer = new byte[size];  
  25.         int ReadBytes;  
  26.   
  27.         while ( (ReadBytes = FromStream.Read(buffer, 0, size)) > 0 )  
  28.         {  
  29.             try  
  30.             {  
  31.                 Stream.Write(buffer, 0, size);  
  32.             }  
  33.             catch (System.IO.IOException /* e */ )  
  34.             {  
  35.                 // Loading is interrupted  
  36.                 break;  
  37.             }  
  38.         }  
  39.   
  40.         Stream.Close();  
  41.   
  42.         Handled = true;  
  43.     }  
  44. }  

[ VB.Net ]
  1. Private Sub f_in_box__control1_OnLoadExternalResourceByRelativePath(ByVal sender As ObjectByVal URL As StringByVal Stream As System.IO.Stream, ByRef Handled As BooleanHandles f_in_box__control1.OnLoadExternalResourceByRelativePath  
  2.   
  3.     Dim FromStream As System.IO.Stream = Nothing  
  4.   
  5.     If URL = "images/embedded_image1.jpg" Then  
  6.         FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image1.jpg")  
  7.     End If  
  8.   
  9.     If URL = "images/embedded_image2.jpg" Then  
  10.         FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image2.jpg")  
  11.     End If  
  12.   
  13.     If URL = "images/embedded_image3.jpg" Then  
  14.         FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image3.jpg")  
  15.     End If  
  16.   
  17.     If URL = "images/embedded_image4.jpg" Then  
  18.         FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image4.jpg")  
  19.     End If  
  20.   
  21.     If URL = "images/embedded_image5.jpg" Then  
  22.         FromStream = Me.GetType().Assembly.GetManifestResourceStream("Sample6_ExternalResourcesEmbedding.embedded_image5.jpg")  
  23.     End If  
  24.   
  25.     If URL = "images/external_image.jpg" Then  
  26.         If OpenJPEGFileDialog.ShowDialog() = DialogResult.OK Then  
  27.             FromStream = OpenJPEGFileDialog.OpenFile()  
  28.         End If  
  29.     End If  
  30.   
  31.     If Not FromStream Is Nothing Then  
  32.   
  33.         ' Also you can write content in a separate thread  
  34.   
  35.         Const Size = 64 * 1024  
  36.         Dim buffer(Size) As Byte  
  37.         Dim ReadBytes As Integer  
  38.   
  39.         While True  
  40.   
  41.             ReadBytes = FromStream.Read(buffer, 0, Size)  
  42.   
  43.             If ReadBytes = 0 Then Exit While  
  44.   
  45.             Try  
  46.                 Stream.Write(buffer, 0, ReadBytes)  
  47.             Catch e As System.IO.IOException  
  48.                 ' Loading is interrupted  
  49.                 Exit While  
  50.             End Try  
  51.   
  52.         End While  
  53.   
  54.         Stream.Close()  
  55.   
  56.         Handled = True  
  57.   
  58.     End If  
  59.   
  60. End Sub  


Copyright © Softanics. All rights reserved.
F-IN-BOX is a trademark of Softanics.
Macromedia and Shockwave Flash are trademarks of Adobe