Flash Player is inserted into the C # application in the form of a COM component. Joined the method is the same as the ordinary COM control. This is a small trial I did in February this year. In fact, the project I did in the first half of the year has always been related to this, so there are still some experiences in this regard. Now due to the start of the company project, it is necessary to familiarize this, then the interface between them, makes the interface between them more versatile. There is an open source project flashcsharp in this regard. But he is just a good control, and the scalability is not very strong. This small trial is a media player, controlled by flash, first familiar with it.
Using system;
Using system.drawing;
Using system.collections;
Using system.componentmodel;
Using system.windows.forms;
Using system.data;
Namespace MediaPlay
{
///
/// Form1 summary description.
/// summary>
Public Class Form1: System.Windows.Forms.form
{
Private axwmplib.axwindowsmediaplayer axwindowsmediaplayer1;
Private axshockwaveflashObjects.axshockwaveflash axshockwaveflash1;
///
/// The required designer variable.
/// summary>
Private system.componentmodel.Container Components = NULL;
Public Form1 ()
{
//
// Windows Form Designer Support
//
InitializationComponent ();
//
// Todo: Add any constructor code after INITIALIZECOMPONENT call
//
AxshockWaveflash1.Movie = Application.startupPath "// VideoControlButtons.swf";
AxWindowsMediaPlayer1.url = Application.startuppath "// movie.avi";
}
///
/// Clean all the resources being used.
/// summary>
Protected Override Void Dispose (Bool Disposing)
{
IF (Disposing)
{
IF (Components! = NULL)
{
Components.dispose ();
}
}
Base.dispose (Disposing);
}
#Region Windows Form Designer Generated Code
///
/// Designer supports the required method - do not use the code editor to modify
/// This method is content.
/// summary>
Private vidinitiRizeComponent ()
{
System.Resources.ResourceManager Resources = New System.Resources.ResourceManager (TypeOf (Form1));
THIS.AXWINDOWSMEDIAPLAYER1 = New AxWMPLIB.AXWINDOWSMEDIAPLAYER ();
This.axshockwaveflash1 = new axshockwaveflashObjects.axshockwaveflash (); ((System.componentModel.isupportInitialize) (this.axwindowsmediaplayer1)). Begininit ();
(System.comPonentModel.isupportInitialize) (this.axshockwaveflash1)). Begininit ();
THIS.SUSPENDLAYOUT ();
//
// AxWindowsMediaPlayer1
//
THIS.AXWINDOWSMEDIAPLAYER1.ANCHOR = System.Windows.Forms.Anchorstyles.top;
THIS.AXWINDOWSMEDIAPLAYER1.ENABED = TRUE;
this.axwindowsmediaplayer1.location = new system.drawing.point (4, 1);
this.axwindowsmediaplayer1.name = "AxWindowsMediaPlayer1";
THIS.AXWINDOWSMEDIAPLAYER1.OCXSTATE = ((System.Windows.Forms.Axhost.State) ("AxWindowsMediaPlayer1.OCxState))));
This.axwindowsmediaplayer1.size = new system.drawing.size (312, 248);
this.axwindowsmediaplayer1.tabindex = 0;
This.axwindowsmediaplayer1.Enter = new system.eventhandler (this.axwindowsmediaplayer1_enter);
//
// axshockwaveflash1
//
This.axshockwaveflash1.Anchor = system.windows.forms.Anchorstyles.bottom;
THIS.AXshockWaveflash1.enabled = True;
this.axshockwaveflash1.location = new system.drawing.point (9, 255);
THIS.AXshockWaveflash1.name = "axshockwaveflash1";
This.axshockwaveflash1.ocxState = ((System.Windows.Forms.Axhost.State) ("AxshockWaveFlash1.OCxState)))
This.axshockwaveflash1.size = new system.drawing.size (300, 150);
this.axshockwaveflash1.tabindex = 1;
This.axshockwaveflash1.fscommand = new axshockwaveflashObjects._ishockwaveflashevents_fscommandeventhandler (this.axshockwaveflash1_fscommand);
//
// Form1
//
THIS.AUTOSCALEBASESIZE = New System.drawing.size (6, 14);
THIS.CLIENTSIZE = New System.drawing.size (320, 398); this.controls.add (this.axshockwaveflash1);
This.Controls.add (this.axwindowsmediaplayer1);
THIS.NAME = "Form1";
THIS.TEXT = "Form1";
(System.comPonentModel.isupportInitialize) (this.axwindowsmediaplayer1). Endinit ();
(System.comPonentModel.isupportInitialize) (this.axshockwaveflash1)). Endinit ();
This.ResumeLayout (false);
}
#ndregion
///
/// The main entry point for the application.
/// summary>
[Stathread]
Static void main ()
{
Application.run (New Form1 ());
}
Private void AxshockWaveFlash1_fscommand (Object Sender, AxshockWaveflashObjects._ishockwaveflashevents_fscommandevent e)
{
Switch (e.command)
{
Case "Pause":
{
AxWindowsMediaplayer1.ctlControls.pause ();
}
Break;
Case "Play": AxWindowsMediaPlayer1.ctlControls.Play ();
Break;
Case "fullscr": Axwindowsmediaplayer1.fullscreen = true;
Break;
Case "close": Application.exit ();
Break;
DEFAULT:
Break;
}
}
Private void AxWindowsMediaPlayer1_enter (Object Sender, System.EventArgs E)
{
}
}
}
Flash is controlled by the fscommand command, FSCommand's format in FSCommand (CommandName, Arg). Use this command to generate an FSCommand event in the C # application. Processing via an EventHandler. This.axshockwaveflash1.fscommand = new axshockwaveflashObjects._ishockwaveflashevents_fscommandeventhandler (this.axshockwaveflash1_fscommand);
And C # can also set parameters to Flash, such as:
String FlashData = "One 2 Thirty Four Fifth Six Seven";
AxshockWaveflash1.Setvariable ("Data", FlashData);
In this case, it can vary via Obejct.Watch () in Flash.