# VBForums UtilityBank > UtilityBank - Tutorials >  Setting up XNA graphics in VB.Net

## dday9

*Contents*
 In this tutorial I will cover the following:
Set up XNA graphics in visual basic.net

A few prerequisites:
Visual Basic.Net 2010 or higherMicrosoft XNA 4.0 or higher

Following my prior tutorial, go ahead and add the correct XNA references and Import:
Microsoft.Xna.FrameworkMicrosoft.Xna.Framework.Graphics

We will first add two variables, the first would be a boolean value set to false. The second will be a GraphicsDevice (documentation), not set up yet.


```
    Private quit As Boolean = False
    Public grafix As GraphicsDevice
```

The next step in our process is to start a boolean function. Now in this function, we will try to set up the graphics device. If for whatever reason we fail, in the form_load event an error will be thrown. 


```
    Private Function initialize(ByRef surface As PictureBox) As Boolean
        Try
            Dim pparam As New PresentationParameters
            pparam.DeviceWindowHandle = surface.Handle
            pparam.IsFullScreen = False

            Dim grafixAdapt As GraphicsAdapter = GraphicsAdapter.DefaultAdapter

            grafix = New GraphicsDevice(grafixAdapt, GraphicsProfile.HiDef, pparam)


            initialize = True
        Catch ex As Exception
            initialize = False
        End Try
    End Function
```

The first thing we declare is a presentation parameter. You can think of presentation parameters kinda similar to data parameters, but for the graphics device. The two properties we set are the device handle, which in this case I'm using a picturebox, as well as setting the full screen to false. There are more properties that you can set, but for the informative process, these will be the only two we are setting. The next thing that we declare is the Graphics adapter. All computers should have 1 graphics card, that's why we set the item to 0(remember index are 0 based). Finally we try to set the graphics device using the variables we just declared. If we suceed then return a true value, and vice-versa.

The next step in our process is to check if we had any errors in setting our graphics device. If we don't have any errors then display the traditional XNA "cornflower blue"!


```
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        If initialize(pbGame) Then
            BackgroundWorker1.RunWorkerAsync()
        Else
            MessageBox.Show("There was a problem initializing XNA.")
            Me.Close()
        End If
    End Sub
```

In our background worker, we call an infinate loop to present the cornflower blue.


```
        Do Until quit = True
            grafix.Clear(Color.CornflowerBlue)
            grafix.Present()
        Loop
```

Now simply debug your program and behold the blues!

More XNA in Vb.Net to come later!

----------


## Shaggy Hiker

This is for whole program XNA development using a game loop. Over in the CodeBank I have an example of using XNA for drawing individual controls within a form that doesn't otherwise use XNA. You might add a tutorial on that, too, as it is a subject that is likely valuable and very poorly covered.

----------

