Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Create your first Web Application with GOA WinForms

0.00/5 (No votes)
2 Jul 2007 1  
This article describes how to create a very simple project using GOA WinForms for Flash

Introduction

This article describes how to create a very simple project using GOA WinForms for Flash. Even if we will focus on the Flash target, the process for creating a project targeting Microsoft Silverlight is very close to the one that is described in the article.

GOA WinForms allows developers to build web applications using their WinForms experiences and skills. It is an implementation of the standard System.Windows.Form .NET library for both Adobe Flash and Microsoft Silverlight. It allows .NET developers to write standard WinForms applications that will run on these two RIA platforms.

GOA WinForms contains the full-featured System.Windows.Forms core library, enabling to freely develop and deploy Flash & Silverlight RIA applications using Microsoft Visual Studio.

The basic package of GOA WinForms is completely free to use and deploy. It includes 40+ standard controls and components.

Using the code

Prerequisites

Creating a GOA Project Using Visual Studio

  • Start Visual Studio 2005
  • On the File menu, click New Project
  • In the New Project" dialog box, under the "GOA Projects" folder, choose GOA Application
  • Name your application "HelloWorld" and click OK

A new Visual Studio project is created.

Open the Form1.ccs file that has been automatically generated. In this file, you can watch the code of an "almost standard" .NET Windows Form holding a button.

Compile and run the HelloWorld application

  • On the Debug menu, click Start
  • A dialog box asking if you would like to build the project is displayed. Click Yes to build the project
  • The application starts. A form holding a button is displayed

Here is what has happened when you have started debugging the application:

  • The code of the application has been compiled using the GOA compiler
  • A swf file ("executable" Flash file) has been generated
  • The swf file has been loaded inside the Visual Studio Internal Web Browser

If you go to the bin\Debug subdirectory of your project using Windows Explorer, you will see two files:

  • The HelloWorld.swf file is the swf file that has been generated by the compiler from the C# code of the project
  • The HelloWorld.swf.html page is a basic HTML page that has been generated to load the HelloWorld.swf file

Note that the project has been compiled using the GOA compiler and not the .NET C# compiler. The GOA compiler allows to generate a swf ("executable" Flash file) from C# code.

Also note the ccs extension of the Form1.ccs file. This is the default C# file extension for GOA.

The swf file that you have just compiled can be run under Flash Player version 7 or above. Nevertheless, it is recommended to target Flash Player version 9 or above.

  1. In the Solution Explorer Right Click your project
  2. In the drop down menu, click the Properties item
  3. On the right of the Property Pages dialog box, select the Build node under the Configuration Properties node
  4. Change the Platform Target value to Flash 9 or higher
  5. Click OK

Now that your platform target is Flash 9, the swf will run a lot faster but it will not be compatible with the earlier versions of the Flash Player.

Add a Button and a Label to Form1

Now that we understand the basics of GOA WinForms for Flash, we can write some code in the HelloWorldForm class to create our Hello World application.

Note that we are coding our project in a standard way as if we were creating a .NET Windows Forms desktop application.

We are adding a label at the top of the form and moving the button at the bottom. When the user will click on the button, the label will display the "Hello World" text.

We are adding a label at the top of the form and moving the button at the bottom. When the user will click on the button, the label will display the "Hello World" text.

  • First let's add a label to the form and move the button at the bottom of the form. The code that follows is very close to any code generated by the Visual Studio Windows Forms Designer:

    public class Form1 : System.Windows.Forms.Form 
    { 
       private Button button1;  
       private Label label1;   
       private System.ComponentModel.Container components = null;  
    
       public Form1()  
       {  
          InitializeComponent();  
       }  
    
       protected override void Dispose(bool disposing)  
       {  
          if (disposing)  
          {  
             if (components != null)  
            {  
               components.Dispose();  
            }  
          }  
          base.Dispose(disposing);  
       }  
    
       private void InitializeComponent()  
       {  
          this.button1 = new System.Windows.Forms.Button();  
          this.label1 = new System.Drawing.Point(84, 140);  
          this.button1.Name = "button1";  
          this.button1.Size = new System.Drawing.Size(104, 36);  
          this.button1.Text = "Click Me";
    
          this.label1.Location = new System.Drawing.Point(40, 44);  
          this.label1.Name = "label1";  
          this.label1.Size = new System.Drawing.Size(200, 44);  
    
          this.Controls.Add(this.label1);  
          this.Controls.Add(this.button1);  
    
          this.ResumeLayout(false);  
       }  
    
       static void Main()  
       {  
          Application.Run(new Form1()); 
       } 
    }  
    

  • We also need to add an event handler to manage the button click event.

    Add the following line in the InitializeComponent method of the form:

    this.button1.Click += new EventHandler(button1_Click);

    And, of course, we also have to add the method that will set the text of the label:

    void button1_Click(object sender, EventArgs e) 
    { 
      this.label1.Text = "Hello World"; 
    }

Before starting the application, let's change the settings in order to start it in an external browser.

  • In the Solution Explorer, right click your project
  • In the drop down menu, click the Properties item
  • On the right of the Property Pages dialog box, select the Debugging node under the Configuration Properties node
  • Change the Start Program Type value to Internet Explorer
  • Click OK

Now, you can start your application.

Points of Interest

This article is only a quick introduction but it shows that it is now possible to create web application using only your WinForms programming skills.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here