HelloWorld VB.NET

From SDL.NET

This tutorial shows how to setup your IDE for use with SDL.NET and then how to write a simple hello world application. The program simply initializes SDL.NET and displays its initial window. We'll be using VB.NET in this version of this tutorial but a C# tutorial is also available (which this tutorial was derived from). It is assumed that you successfully installed SDL.NET (Help With Installation). You can use any VB.NET IDE, Visual Studio and SharpDevelop being the most popular, but this tutorial will be targeted to those who use Visual Studio. The most important thing is that you know how to use it.

Table of contents

Setting Up The IDE

Once you have successfully downloaded/installed SDL.NET, you will be able to use it in your development environment by making reference to it in your project.

  1. Start up a Windows Application project.
  2. Add reference to SDL.NET. To do this, you:
    1. Right click on References in the Solution Explorer.
    2. Choose Add Reference.
  3. Set the startup object to be "Sub Main". To do this, you:
    1. Right-click on the "HelloWorld" project in the Solution Explorer.
    2. Click the drop-down box next to "startup object" and select "Sub Main" (NOTE: If you are using Visual Studio 2005, the "enable application framework" option must be unchecked in order to be able to select "Sub Main")
    3. Click OK.
  4. Right-click on the "Form1.vb" file and select "Delete".
  5. Right-click on the "HelloWorld" project entry in the Solution Explorer and create a module called "HelloWorld"
  6. Double-click on "HelloWorld.vb" to open it.
  7. Delete all code from "HelloWorld.vb".
  8. Paste the "HelloWorld" code shown below into "HelloWorld.vb"
  9. Press "F5" to compile and run the code.

Hello World

We will use a preconstucted code base for the example and then take a closer look at it later. In this section we will use SDL.NET to create a new SDL window.

Imports SdlDotNet.Core
Imports SdlDotNet.Graphics

Module HelloWorld
    Public Sub Main()
        Video.SetVideoMode(400, 300)
        Video.WindowCaption = "Hello World!"

        AddHandler Events.Quit, AddressOf Quit
        Events.Run()
    End Sub

    Public Sub Quit(ByVal sender As Object, ByVal e As QuitEventArgs)
        Events.QuitApplication()
    End Sub
End Module

As you can see in this small example we set up SDL.NET with a window of 400 by 300 and change the caption of the window to "Hello World!". Now try running your application and see what it gives you.

Dependencies

What happened! If you ran your application, it may have asked for SDL.dll. This is because SDL.NET uses SDL in its background and requires it to run. You're going to have to go into the SDL.NET directory and find the win32 dependancies folder. Copy all (or just the required ones) from that folder into your build directory of your project and try to run it again. Better yet, copy the dll files to 'C:\winnt\system32' so the files will always be available. You should now see the Hello World example run.

Hello World Example
Enlarge
Hello World Example

Conclusion

This is just a small article showing how to initialize SDL.NET. The example itself is not really that exciting but it shows that you know how to make reference to SDL.NET and initialize a window. On the next tutorial, Surfaces, we'll go over how to get some nice graphics on the screen.

See Also