Click here to Skip to main content
15,117,830 members
Articles / Programming Languages / C#
Posted 21 Aug 2009

Tagged as


2 bookmarked

A Mentor’s Example Article

Rate me:
Please Sign up or sign in to vote.
1.25/5 (3 votes)
21 Aug 2009CPOL6 min read
An Article to Help the New Writer Understand Sone Helpful Concepts

A Mentor’s Example Article


One of the criticisms about technical documentation is that the material lacks an explanation of any underlying principles behind a particular topic. This article may not do any better, but will at least try to show the new writer how to play a .wmv file on a Windows Forms application, while explaining how the article is written. Many try to use the article submission wizard to then preview their article before submission and find that it does not seem to adhere to that article submission’s requirements. A simple approach to this issue would be to write a simple web page. HTML is not a programming language, but a set of tags that reveal where the presentation content will be placed (or marked) on a web page. For example, I will insert an image file, use the text written above, insert the needed HTML tags code in notepad, and save it as an HTML file on my desktop:


I name the file and add an .html file extension, avoiding saving it as a text file. Since I have saved it to my desktop, I will double click the file to open it. I saved the sample image and copied it to my desktop, stating the path following the IMG tag:


Notice that I used head and body tags. We do not use them with the article submission wizard. Now how did I get a picture of the files that I just wrote? If you use Windows Vista, there is a feature called “Tablet PC”. The “Snipping Tool” is found in the accessories folder in the start menu. It has a small icon: choose the hand, or the window choice. From there place the hand on the edge of the actual image and it will take a snapshot. You can save under a name of your choice in the Pictures folder. Now after going to pictures folder, right click the image and open it with the Microsoft Office Picture Manager. Go to “Pictures” on the toolbar, and choose resize picture. The article submission wizard does not permit images over 600 by 400 pixels. Resize the picture to a practical size that will not crowd the page or consume bandwidth. Afterwards, when you are at the uploading file stage of the article submission process, the Code Project upload file control will help you browse your own folders to add to what will be inserted and where. When you are writing your article, try clicking the bent lines control: the one that switches from text to the HTML editor. When you begin, try to use only the HTML that you need, deleting the rest. Always click work in progress and check the agreement check box that adheres to the Code Project’s rights involving a site visitor’s article submission.

Recall that this article intends to show how to play audio and video on a Windows Forms application. A Windows Forms application provides a user interface where controls can be dragged and dropped onto the surface. But if I were to write code for a basic Windows form, it would appear as follows in the article submission wizard:


The pre tags contain the code blocks that correspond to the formatted format, as seen in the upper-left hand corner of the article submission wizard. One important note on using the HTML source view: if you write an article in C, C++, Perl, HTML, or any web development technology, then using these tags < > will not appear in the text view, which is the view that gets published. For example, if I wrote:

#include <stdio.h><stdio.h>

#include <iostream><iostream>

it would appear as:


The redirection symbols that are used in header files, HTML tags, Perl operators, and the like, do not appear when you are using the HTML editor to write your article. Be careful and keep track of when you use such symbols. Note them, and then add them manually in your text view. When you return to the HTML editor, you will find that code has been generated to contain those symbols. Now here is the output of the code when compiled on the command line using the /target:winexe flag:


Using a Windows Form to play .wmv files, .avi files, .mp3 files, etc

I assume you have a copy of Visual Studio 2008. It is easy to download, and then burn the ISO as an image file to a DVD. Go to projects, choose new, and choose Visual C# Windows Forms application, and name it whatever you would like. In the mean time, go to your sample video folder, copy a .wmv file, and paste it to your desktop. I am going to assume that your file is called bear.wmv. Now right-click on an empty area of the toolbox and choose “add items”. Go to the COM tab, and check Windows Media Player. This article assume that you have Windows Media Player installed on your machine. If you do not, then download it and install it. After clicking OK, you will find that a Windows Media Player control can be dragged and dropped onto the surface of your loaded form:


In the lower right-hand corner, notice the Windows Media Player control, a COM component, has been added to be dragged and dropped onto the UI surface. Now all we need to do is write a little code. Not too hard, huh? So we double the form (and not the media player that we dragged and dropped onto the surface. Here is how the code looks:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyForm
    public partial class Form1 : Form
        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            string fpath = @"c:\users\dave\desktop\bear.wmv";
            WindowsMediaPlayer1.settings.autoStart = false;
            WindowsMediaPlayer1.URL = fpath;



I created a variable of type string, named it fpath, and assigned it the value of the path where the .wmv file is located. The WindowsMediaPlayer1 control has settings called autostart that we set to false, because we want the form to load the interface that contains the control. The URL property of the WindowsMediaPlayer1 control could also be the URL of something on the internet. Here it is a file path. We build the container solution and then select “run without debugging”:


We can here the audio and see the video. The code for the program file is shown below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace MyForm
    static class Program
        /// <summary />
        /// The main entry point for the application.
        /// </summary />
        static void Main()
            Application.Run(new Form1());

If you are a new writer as I am, then we must understand that technical writing involves both learning the programming language and the technology that builds it. It is not just a matter of writing code to compile, but using the technology provided to write the code that will perform a service, function, or task that could not ordinarily be performed by a human. That is, if you have Windows Media Player installed on your machine, then you do not need to drag and drop it as a control onto a form. But if you understand why dragging and dropping generates code, you can focus on understanding the event handlers that enable the controls to perform an action. This technology is called OLE 2, and is a technology in its own right. It is the foundation for COM, but understanding that then relieves of the pains of COM to focus on managed code. Then, if you try to submit material for print, then try to keep it simple by using basic image insertion , HTML paragraph tags, header tags, ordered list tags, unordered list tags, pre tags, etc. You are adhering to an article submission wizard and not building a web page. But your rough draft in MS Word should add the head the body tags so that you can copy and paste the material to notepad and save it as an HTML file. Reading that web page aloud will indicate if it something that will be a contribution.


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


About the Author

Software Developer Monroe Community
United States United States
No Biography provided

Comments and Discussions

GeneralMy vote of 2 Pin
createelement20-Oct-10 6:47
Membercreateelement20-Oct-10 6:47 
GeneralMy vote of 1 Pin
Kelvin Armstrong12-Oct-10 5:41
MemberKelvin Armstrong12-Oct-10 5:41 
GeneralMy vote of 1 Pin
seeblunt21-Aug-09 17:41
Memberseeblunt21-Aug-09 17:41 

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.