Netika Technologies
Demos Downloads Community

Create a Visual Basic “Hello World” Application with GOA for Silverlight

Download the Visual Basic templates

Download the sample project

Introduction

This QuickStart Topic describes how to create a basic "Hello World" project using GOA for WinForms for Silverlight.

Prerequisites: Silverlight (available from the Silverlight website):

  • Microsoft Silverlight 2.0 Beta 1
  • Microsoft Visual Studio 2008
  • Microsoft Silverlight 2.0 Tools for Visual Studio 2008

GOA WinForms (available from the NETiKA Technologies site):

  • GOA WinForms for Silverlight or GOA WinForms Professional for Silverlight

Install the Visual Basic GOA for WinForms Project Templates

The current release of GOA WinForms for Silverlight does not provide templates to create a GOA for WinForms Visual Basic project.

Before reading this QuickStart you will need to download the templates and install them: Visual Basic templates

  • GOA for WinForms Visual Basic project Template
  • GOA for WinForms Professional Visual Basic project Template

The templates are provided as vsi files. To install a template, double-click on the vsi file.

Creating a GOA Project Using Visual Studio

  • Start Visual Studio 2008.
  • On the File menu, click New Project.
  • In the Project types tree view on the left of the New Project dialog box, select the Visual Basic node.
  • In the Templates list on the right, select GOA WinForms VB Application.
  • Name your application "HelloWorld" and click OK.

A new Sliverlight Visual Studio project is created.

Creating an ASP .NET Web Application Using Visual Studio

  • In the Solution Explorer, right click the Solution node, in the drop down menu, select the Add New Project item.
  • In the Project types tree view on the left of the New Project dialog box, select the Visual Basic node.
  • In the Templates list on the right, select ASP .NET Web Application.
  • Name your application "HelloWorldWeb" and click OK.

Link the "HelloWorld" project and the "HelloWorldWeb" project

  • In Solution Explorer, right-click the "HelloWorldWeb" project node you just created, and select Add Silverlight Link from the context menu.
  • When prompted to select a project, choose the "HelloWorld" project, and then click OK.
  • When prompted whether you want to enable Silverlight debugging for this project, click Yes.
  • Right-click the "HelloWorldWeb" ASP.NET project node again, and click Set as Startup Project.
  • Delete the Default.aspx page from the ASP.NET project.

Compile and run the HelloWorld application

  • Make sure the "HelloWorldWeb" project is the Startup project.
  • In the Solution Explorer, right click the TestPage.html file and, in the drop down menu, select the Set As Start Page item.
  • On the Debug menu, click Start Debugging.
  • When you are prompted to modify the Web.config file to enable debugging, click OK.
  • The application starts. A form holding a button is displayed.

Explore the "Hello World" project

The Hello World project is mainly made of standard Silverlight 2 project files. If you need an introduction on the files that are used by a basic Silverlight project, please read the "How to: Create a Silverlight Project" QuickStart.

Explore the references

  • In the Solution Explorer right click the HelloWorld project node.
  • At the bottom of the drop down menu, select the Properties item.
  • In the Project Properties window, select the references tab.

Among the assemblies referenced by your project, you can see a reference to the Goa.Windows.Forms assembly. The Goa.Windows.Forms assembly holds the System.Windows.Forms namespace that we are using in this sample. It also provides all the GOA basic features and it includes a large set of controls.

More advanced controls are provided in the GOAGrid and GOAToolkit assemblies.

Explore the MyForm.vb file

  • In the Solution Explorer double click the MyForm.vb file.

The content of the file is displayed in the Visual Studio Code Editor. In this file, you can watch the code of an "almost standard" .NET Windows Form holding a button. A Shared Main method has been created:

Public Shared Sub Main()         Application.Run(New MyForm)     End Sub

GOA will use this method as an entry point in order to start MyForm when requested.
Note that this method must be shared.

Explore the Page.xaml file

  • In the Solution Explorer double click the Page.xaml file.
  • The content of the file is displayed in the Visual Studio Code Editor.

The Page.xaml file holds the description of the canvas that Silverlight displays when the application starts. It also uses some GOA feature in order to display MyForm WinForm inside the root canvas:

  • The following attribute as been added to the root tag:
    xmlns:goa="clr-namespace:NETiKA.Silverlight;assembly=ClientBin/Goa.Windows.Forms.dll"
    This attribute is used to map an xmlns to reference the Goa.Windows.Forms assembly.
  • The following element has been added inside the parent canvas of Page.xaml:
    <goa:WinFormHost Width="640"                  Height="480"                  Canvas.Left="0"                  Canvas.Top="0"                  FormClass="HelloWorld.MyForm"/>
    The WinFormHost element is used to display the forms created using the System.Windows.Forms namespace. The main attribute of this element is "FormClass". You can use this attribute to tell which form must be displayed in the WinFormHost element. The value you set in the FormClass must have the following format: "NameSpaceOfTheForm.ClassNameOfTheForm". Note: The form that will be displayed in the WinFormHost element must provide an entry point using a public shared Main method.

Add a button and a label to the MyForm form

Now that we understand the basics of GOA WinForms for Silverlight, we can write some code in the MyForm 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 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:
    '. . .       Private components As System.ComponentModel.IContainer       Friend WithEvents Button1 As System.Windows.Forms.Button     Friend WithEvents Label1 As System.Windows.Forms.Label     Private Sub InitializeComponent()         Me.Button1 = New System.Windows.Forms.Button         Me.Label1 = New System.Windows.Forms.Label         Me.SuspendLayout()         '         'Button1         '         Me.Button1.Location = New System.Drawing.Point(50, 50)         Me.Button1.Name = "Button1"         Me.Button1.Text = "Click Me"           '         'Label1         '         Me.Label1.Location = New System.Drawing.Point(50, 30)         Me.Label1.Text = "Label1"         Me.Label1.Size = New System.Drawing.Size(200, 44)         '         'Form1         '         Me.Controls.Add(Me.Label1)         Me.Controls.Add(Me.Button1)         Me.Text = "Form1"         Me.ResumeLayout(False)       End Sub       '. . .  
  • We also need to manage the button click event. Add the Button1_Click method that will set the text of the label:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         Me.Label1.Text = "Hello World"     End Sub

Congratulations, you can start your first GOA WinForms VB application.

Download the Visual Basic templates

Download the sample project