Click here to Skip to main content
15,389,177 members
Articles / Programming Languages / C#
Posted 10 Aug 2013

Tagged as


19 bookmarked

Playing Flash Files (SWF) in C# Form

Rate me:
Please Sign up or sign in to vote.
4.85/5 (15 votes)
10 Aug 2013CPOL3 min read
In this tip for beginners, we will review how to play a shockwave file (.SWF) in our form in the easiest and fastest way by using Shockwave flash object component.


Maybe sometimes you want to play a shockwave flash file (.swf format) in your C# or VB Visual Studio form. There are many ways to do it, but the easiest way is using its component which is available for use. In this tip for beginners, we will review how to play a shockwave file (.SWF) in our Visual Studio form with the easiest and fastest way by using Shockwave flash object component.

This component is located at %systemroot%\system32\macromed\flash9c.ocx and if you can't find it, you must install the latest version of Adobe Macromedia Flash Player. With this component, you can play all .swf files in order to show them in your projects and not reference which kind of flash file you use (a flash game, a flash banner or something else).

Using the Code

So for doing what we want, we must follow the steps given below:

  1. Add Shockwave flash object to Toolbox (with brief explanation): At first, we need to add Shockwave flash object component to our Toolbox. Generally, for adding a component to toolbox, we can right-click on Toolbox window and then click on choose items.

    Next in Choose toolbox items window, we can find and add each component we want and in this tip, we must go to Com components tab and add Shockwave flash object from there to toolbox. Now, you can see that component in your toolbox.

  2. Add to form: Now you must Drag & Drop the component to your form.

    Tip: One of the famous errors which you can be forced into is error in importing your component to your Visual Studio form. If you are forced to “Failed to import the ActiveX control. Please ensure it is properly registered” error, rebuilding project can help you. This error usually happens when you drag and drop the ActiveX component to a form and rebuilding the project will help you to remove this error. But, I found a solution here for solving this problem forever. Also, if you need a way for registering it manually, this link which I found can help you.

  3. Setting address of swf file to your object: Now you can set your swf file address to your object in any way you want. For example, in C#, you can use this code for playing sample.swf flash file:
    axShockwaveFlash1.Movie = Application.StartupPath + @"\sample.swf";  

    Some simple commands of this component are:

    Playing Flash: AxShockwaveFlash.Play()
    Pausing Flash: AxShockwaveFlash.Stop()
    URL Source of Flash file: AxShockwaveFlash.Movie = FilePath & "\FileName.swf" 

    Other commands properties of this component are:

    1. Loop: which in "True" mode helps to playing flash file continuously
    2. Quality: which in default value shows your flash file in its best quality
    3. Menu: which you can disable right click menu of flash object (settings) by it
    4. Framenum: by this, you can choose your start frame of your swf file
    5. EmbedMovie: make your flash file source embed to your solution
    6. BGColor: background color of your file when it starts to play
    7. AlignMode, AllowFullscreen, CTLScale, SAlign, WMode are used for positioning and setting view mode

In Other Languages

Originally, this beginner tip was published in Persian language on my website, then I translated it to English because I thought it might be helpful for people who have just started coding in C#!

Iranian friends can find the original article in Persian on Sourcenevis.

Sample Solution

A project of this tip can be downloaded here.

In this sample, I added a Shockwave flash object to the form and then created play, stop commands for them. Also, I link URL of flash file into debug folder which is contained with the main EXE file.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Amir Mohammad Nasrollahi
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pin
Hasmukh Savaliya10-Jun-16 21:49
professionalHasmukh Savaliya10-Jun-16 21:49 
QuestionPlaying movie from memorystream Pin
Member 217646726-Aug-14 23:02
MemberMember 217646726-Aug-14 23:02 
Questionتشکر Pin
saeed_smco5-Aug-14 7:20
Membersaeed_smco5-Aug-14 7:20 
AnswerRe: تشکر Pin
Amir Mohammad Nasrollahi5-Aug-14 19:47
MemberAmir Mohammad Nasrollahi5-Aug-14 19:47 
Questionfrom code? Pin
Chris Anders4-Aug-14 23:36
MemberChris Anders4-Aug-14 23:36 
GeneralMy vote of 5 Pin
ketan italiya12-Aug-13 21:46
Memberketan italiya12-Aug-13 21:46 
GeneralRe: My vote of 5 Pin
Amir Mohammad Nasrollahi12-Aug-13 23:06
professionalAmir Mohammad Nasrollahi12-Aug-13 23:06 
QuestionImage missing Pin
Joezer BH11-Aug-13 1:31
professionalJoezer BH11-Aug-13 1:31 
AnswerRe: Image missing Pin
Amir Mohammad Nasrollahi11-Aug-13 1:56
professionalAmir Mohammad Nasrollahi11-Aug-13 1:56 
GeneralMy vote of 5 Pin
Ehsan Azami10-Aug-13 8:43
professionalEhsan Azami10-Aug-13 8:43 
AnswerRe: My vote of 5 Pin
Amir Mohammad Nasrollahi10-Aug-13 8:44
professionalAmir Mohammad Nasrollahi10-Aug-13 8:44 
GeneralMy vote of 5 Pin
Reza Khan Mohammad10-Aug-13 8:36
professionalReza Khan Mohammad10-Aug-13 8:36 
AnswerRe: My vote of 5 Pin
Amir Mohammad Nasrollahi10-Aug-13 8:37
professionalAmir Mohammad Nasrollahi10-Aug-13 8:37 
GeneralRe: My vote of 5 Pin
Member 124375602-Jun-18 0:22
MemberMember 124375602-Jun-18 0:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.