I saw several posts about it, where two solutions where presents:
1. Add WebBrowser Control and just nevigate to the "test.swf" file.
2. Create COM object of ADOBE MACROMEDIA.
I liked the 1st option more, because I don't need to handle COM objects (and to add another DLL to the app).
Here is the code I used:
WebBrowser wb = new WebBrowser();
//wb.Location = SOME LOCATION
//wb.Size = SOME SIZE
wb.AllowNavigation = false;
wb.IsWebBrowserContextMenuEnabled = false;
this.Controls.Add(wb); // this = FORM
wb.Navigate(@"C:\test.swf");
//wb.Location = SOME LOCATION
//wb.Size = SOME SIZE
wb.AllowNavigation = false;
wb.IsWebBrowserContextMenuEnabled = false;
this.Controls.Add(wb); // this = FORM
wb.Navigate(@"C:\test.swf");
BUT, Then i noticed that when a pc do NOT have Adobe (Macromedia) Flash player installed, the webbrowser display a big red X.
SO, before I use the FLASH image in my winform application, I needed to check if FLASH player is INSTALLED or not!
The idea is to check the registry for:
HKEY_LOCAL_MACHINE\SOFTWARE\Macromedia\FlashPlayer\CurrentVersion
And indeed it worked!
Here is the full code for testing if FLASH installed (and also get the major Version):
internal static int? GetFlashPlayerVersion()
{
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Macromedia\FlashPlayer"))
{
if (rk != null)
{
string version = rk.GetValue("CurrentVersion") as string;
if (string.IsNullOrEmpty(version) == false)
{
int idx = version.IndexOf(",");
if (idx > 0)
{
int value;
if (int.TryParse(version.Substring(0, idx), out value) == true)
{
return value;
}
}
}
}
}
return null;
}
{
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Macromedia\FlashPlayer"))
{
if (rk != null)
{
string version = rk.GetValue("CurrentVersion") as string;
if (string.IsNullOrEmpty(version) == false)
{
int idx = version.IndexOf(",");
if (idx > 0)
{
int value;
if (int.TryParse(version.Substring(0, idx), out value) == true)
{
return value;
}
}
}
}
}
return null;
}
And the code which using the method:
int? flashVersion = WindowsUtils.GetFlashPlayerVersion();
if (flashVersion.HasValue == true && flashVersion > 6)
{
WebBrowser wb = new WebBrowser();
wb.AllowNavigation = false;
wb.IsWebBrowserContextMenuEnabled = false;
this.Controls.Add(wb); // this = FORM
wb.Navigate(@"C:\test.swf");
}
if (flashVersion.HasValue == true && flashVersion > 6)
{
WebBrowser wb = new WebBrowser();
wb.AllowNavigation = false;
wb.IsWebBrowserContextMenuEnabled = false;
this.Controls.Add(wb); // this = FORM
wb.Navigate(@"C:\test.swf");
}
Best regards,
MDB-Blog
thanks it helps me..
ReplyDelete