flash内嵌于C#程序中的应用
2004-09-27 10:31
316 查看
flash player是以一个com+组件的形式插入到C#应用程序中的. 加入的方法和普通com+控件一样.这是我今年2月做的一个小试验。事实上我上半年做的项目一直跟这方面有关,所以对这方面还是有一些经验的。现在由于公司项目的启动,所以要对这个熟悉一下,然后整以成熟的方法,使它们之间的接口更有通用性。这方面有一个开源项目flashCsharp做得还不错。但他只是对文件控制不错,扩展性不是很强。这个小试验是一个媒体播放器,由flash来控制,先熟悉一下。
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace mediaplay { /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1; private AxShockwaveFlashObjects.AxShockwaveFlash axShockwaveFlash1; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // axShockwaveFlash1.Movie=Application.StartupPath+"//videoControlButtons.swf"; axWindowsMediaPlayer1.URL=Application.StartupPath+"//movie.avi"; } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { 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.Enabled = true; this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(4, 1); this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1"; this.axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("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)(resources.GetObject("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); } #endregion /// <summary> /// 应用程序的主入口点。 /// </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是通过fscommand命令来控制的, fscommand在flash中的格式是fscommand(commandname,arg)。使用了这个命令就会在C#应用程序中产生一个fscommand事件.通过一个EventHandler来处理。 this.axShockwaveFlash1.FSCommand += new AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEventHandler(this.axShockwaveFlash1_FSCommand);
而C#中也可以向flash设置参数,如:
string flashData = "一二三四五六七"; axShockwaveFlash1.SetVariable("data",flashData);
这样的话可以在flash中通过Obejct.watch()得到变化。
相关文章推荐
- 在C#中winform程序中应用nlog日志工具
- C#的WinForm程序应用了XP主题样式之后,ShowDialog方法出现问题的解决
- C#开发微信门户及应用(47) - 整合Web API、微信后台管理及前端微信小程序的应用方案
- 利用c#制作托盘程序,并禁止多个应用实例运行
- C#窗体内嵌外部程序(cmd.exe)的显示(转载)
- C#打开程序的相关应用
- 利用c#制作托盘程序,并禁止多个应用实例运行
- 插件式程序开发及其应用(C#)
- C#为winForm程序打包发布应用
- C#如何为winform程序打包发布应用(图解)
- 插件式程序开发及其应用(C#) - 2(完成)
- C#+flash socket 聊天程序
- (转)在c# winform程序里嵌入FLASH
- 使用.net框架应用C#语言开发窗口程序的一些注意事项
- C# 系统应用之调用SDelete程序粉碎文件及基础原理知识
- c#Winform程序的toolStripButton自定义背景应用示例源码
- C#窗体内嵌外部程序(cmd.exe)的显示
- 我的 C#+flash socket 聊天程序(C#源代码)
- 【阶段总结】关于C# WinForm程序的一些应用总结
- 编写高质量代码改善C#程序的157个建议——建议71:区分异步和多线程应用场景