C# winfrom中Flash播放使用axShockwaveFlash控件设置透明XP出现白色背景解决办法,仿QQ魔法表情效果

 //播放时  图片周围有锯齿白边出现    反锯齿处理暂无解决办法、 如有大神 请给我留言

 

新Form    AllowDrop True

引用using System.IO;

拖1个Button

        public Form1()
        {
            InitializeComponent();
        }

 

    string fileName;
        String extendedName;
        String fileName1;

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();                //new一个方法
            ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); //定义打开的默认文件夹位置
            ofd.ShowDialog();          //显示打开文件的窗口
            fileName = ofd.FileName;                //获得选择的文件路径
            extendedName = Path.GetExtension(fileName);       //获得文件扩展名
            fileName1 = Path.GetFileName(fileName);


            PlayFlash f = new PlayFlash(fileName);
            f.Show();


        }

 

 

 //拖入

private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.Copy;
            }
        }

//拖入操作释放

        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] MyFiles = (string[])(e.Data.GetData(DataFormats.FileDrop));
                if (MyFiles.Length > 0)
                {
                    PlayFlash f = new PlayFlash(MyFiles[0]);//播放窗体传值
                    f.Show();//播放窗体显示
                }
            }
        }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

新建Form

拉一个webBrowser

拖1个timer

设计Form背景为透明等属性

        /// <summary>
        /// 存放Flash路径
        /// </summary>
        string playFile = "";


        public string Isplay;
      
       

        /// <summary>
        /// 获取Flash路径并渲染窗体
        /// </summary>
        /// <param name="file"></param>
        public Form1(string file)
        {
            playFile = file;
            InitializeComponent();
        }

 private void Form1_Load(object sender, EventArgs e)
        {
            //新的文档
            webBrowser1.Navigate("about:blank");

            //判断文档是否在加载
            while (webBrowser1.IsBusy)
            {
                Application.DoEvents();
            }
          
            webBrowser1.Document.Write("<HTML>");
            webBrowser1.Document.Write("<HEAD>");
            webBrowser1.Document.Write("<TITLE>");
            webBrowser1.Document.Write("</TITLE>");
            webBrowser1.Document.Write("<script type='text/javascript' language='javascript'>");
            webBrowser1.Document.Write("function a() {");
            webBrowser1.Document.Write("var ab= document.swf.IsPlaying();");
            webBrowser1.Document.Write("var d = document.getElementById('xxx');");
            webBrowser1.Document.Write("d.value = ab;");
            webBrowser1.Document.Write(" }");
            webBrowser1.Document.Write("</script>");
            webBrowser1.Document.Write("</HEAD>");
            webBrowser1.Document.Write("<BODY>");
            //网页效果输出Flahs
            webBrowser1.Document.Write(string.Format("<object  classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"100%\" height=\"100%\" id=\"swf\"> <param name=\"wmode\" value=\"transparent\"><param name=\"movie\" value=\"{0}\"> <param name=\"quality\" value=\"high\"><param name=\"LOOP\" value=\"false\" /></object>", playFile));
            webBrowser1.Document.Write("<input id=\"xxx\" type=\"hidden\" runat=\"server\" /></BODY>");
            webBrowser1.Document.Write("</HTML>");


            timer1.Interval = 50;
            timer1.Enabled = true;

        }

 

 


        int sum = 0;

 

        private void timer1_Tick(object sender, EventArgs e)
        {
            webBrowser1.Document.InvokeScript("a");

            Isplay = webBrowser1.Document.All["xxx"].GetAttribute("value");
            if (Isplay == "false")
            {
                    timer1.Enabled = false;
                    this.Close();
            }
            sum = sum + 1;
            if (sum > 100)
            {
                timer1.Enabled = false;
                this.Close();
            }
        }

你可能感兴趣的:(Flash)