Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Device Class
Collapse the table of content
Expand the table of content

Device Class

The parent object of all graphical objects in the scene.

Namespace: Microsoft.WindowsMobile.DirectX.Direct3D
Assembly: Microsoft.WindowsMobile.DirectX (in microsoft.windowsmobile.directx.dll)

Public Class Device
	Implements IDisposable
Dim instance As Device

public class Device implements IDisposable
public class Device implements IDisposable
Not applicable.

A device performs primitive-based rendering, creates resources, handles system-level variables, and gets and sets palettes.

The following code example creates a device.

Public Class Form1
    Inherits Form
    ' Set global variables for this project.
    Private device As Device = Nothing
    Public Sub New()
        ' Set the initial size and caption of the form.
        Me.ClientSize = New System.Drawing.Size(400, 300)
        Me.Text = "D3D Tutorial 01: CreateDevice"

    End Sub 'New

    Public Function InitializeGraphics() As Boolean
            ' Set up presentation parameters and create the Direct3D
            ' device.
            Dim presentParams As New PresentParameters()
            presentParams.Windowed = True
            presentParams.SwapEffect = SwapEffect.Discard
            device = New Device(0, DeviceType.Default, Me, CreateFlags.None, presentParams)
            Return True
            Return False
        End Try

    End Function
    Private Sub Render()
        If device Is Nothing Then
        End If
        'Clear the backbuffer to a blue color. 
        device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0F, 0)
        'Begin the scene.

        'Render scene objects, if desired.
        'End the scene.

    End Sub
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        ' Render on painting.
    End Sub

    Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
        If Fix(System.Convert.ToByte(e.KeyChar)) = Fix(System.Windows.Forms.Keys.Escape) Then
            ' Handle the ESC key being pressed.
        End If

    End Sub

    Shared Sub Main()

        Dim DeviceForm As New Form1()
            If Not DeviceForm.InitializeGraphics() Then
                ' Initialize Direct3D.
                MsgBox("Could not initialize Direct3D.  This tutorial will exit.")
            End If

            'While the form is still valid, render and process messages.
            'While DeviceForm.Created
            '    DeviceForm.Render()
            '    Application.DoEvents()
            'End While
        End Try

    End Sub
End Class


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Compact Framework

Supported in: 2.0

Community Additions

© 2015 Microsoft