I'm having an issue with DirectX9 and VB.Net with resizing. Whenever the window is resized, the program locks up. Everything else is working fine though. If anyone has any suggestions on what I should do let me know. Thanks in advance. Here's my code I currently have:

vb.net Code:
  1. Option Explicit On
  2. Option Strict On
  3.  
  4. Imports Microsoft.DirectX
  5. Imports Microsoft.DirectX.Direct3D
  6.  
  7. Public Class frmMain
  8.  
  9.     Private Const COLOR_DEPTH_16_BIT As Format = Direct3D.Format.R5G6B5
  10.     Private Const COLOR_DEPTH_24_BIT As Format = Direct3D.Format.A8R8G8B8
  11.     Private Const COLOR_DEPTH_32_BIT As Format = Direct3D.Format.X8R8G8B8
  12.  
  13.     Private Direct3D_Device As Direct3D.Device
  14.  
  15.     Private Fullscreen_Enabled As Boolean
  16.     Private Running As Boolean = True
  17.  
  18.     Private Vertex_List As CustomVertex.TransformedColoredTextured() = New CustomVertex.TransformedColoredTextured(0 To 3) {} 'create an array of vertices
  19.     Private Texture As Direct3D.Texture
  20.  
  21.     Private Function Create_TLVertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal RHW As Single, ByVal Color As Integer, ByVal TU As Integer, ByVal TV As Integer) As CustomVertex.TransformedColoredTextured
  22.  
  23.         Create_TLVertex.Position = New Vector4(X, Y, Z, 1)
  24.         Create_TLVertex.Rhw = RHW
  25.         Create_TLVertex.Color = Color
  26.         Create_TLVertex.Tu = TU
  27.         Create_TLVertex.Tv = TV
  28.  
  29.     End Function
  30.  
  31.     Private Sub DirectX9_Initialize()
  32.  
  33.         Dim Display_Mode As Direct3D.DisplayMode
  34.         Dim Direct3D_Window As PresentParameters = New PresentParameters
  35.  
  36.         If Fullscreen_Enabled = True Then
  37.             Display_Mode.Width = 800
  38.             Display_Mode.Height = 600
  39.             Display_Mode.Format = COLOR_DEPTH_16_BIT
  40.             'Check to see if fullscreen mode is supported before you use it.
  41.             If Direct3D.Manager.CheckDeviceType(0, Direct3D.DeviceType.Hardware, Display_Mode.Format, Display_Mode.Format, False) Then
  42.                 ' Perfect, this is valid
  43.                 Direct3D_Window.Windowed = False
  44.                 Direct3D_Window.BackBufferCount = 1
  45.                 Direct3D_Window.BackBufferWidth = Display_Mode.Width
  46.                 Direct3D_Window.BackBufferHeight = Display_Mode.Height
  47.             Else
  48.                 MessageBox.Show("Your video card doesn't support this screen resolution.", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
  49.             End If
  50.         Else
  51.             Direct3D_Window.Windowed = True
  52.         End If
  53.  
  54.         Direct3D_Window.SwapEffect = SwapEffect.Copy
  55.         Direct3D_Window.BackBufferFormat = Display_Mode.Format
  56.  
  57.         'Create our device
  58.         Direct3D_Device = New Direct3D.Device(0, Direct3D.DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Direct3D_Window)
  59.  
  60.     End Sub
  61.  
  62.     Private Sub Create_Polygon()
  63.  
  64.         Vertex_List(0) = Create_TLVertex(0, 0, 0, 1, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 0)
  65.         Vertex_List(1) = Create_TLVertex(50, 0, 0, 1, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 0)
  66.         Vertex_List(2) = Create_TLVertex(0, 50, 0, 1, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 1)
  67.         Vertex_List(3) = Create_TLVertex(50, 50, 0, 1, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 1)
  68.  
  69.     End Sub
  70.  
  71.     Private Sub Draw_Polygon()
  72.  
  73.         Direct3D_Device.VertexFormat = CustomVertex.TransformedColored.Format
  74.         Direct3D_Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Vertex_List)
  75.  
  76.     End Sub
  77.  
  78.     Private Sub Game_Loop()
  79.  
  80.         Do While Running = True
  81.             Direct3D_Device.Clear(ClearFlags.Target, Color.Black, 1.0, 0)
  82.             Direct3D_Device.BeginScene()
  83.             'Rendering code goes here.
  84.             Create_Polygon()
  85.             Draw_Polygon()
  86.             Direct3D_Device.EndScene()
  87.             Direct3D_Device.Present()
  88.             Application.DoEvents()
  89.         Loop
  90.  
  91.     End Sub
  92.  
  93.     Private Sub Main()
  94.  
  95.         If MessageBox.Show("Click Yes to go to full screen (Recommended)", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes Then
  96.             Fullscreen_Enabled = True
  97.         End If
  98.  
  99.         With Me
  100.             .Show()
  101.             .SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True) 'Do not draw forms background
  102.             .Text = "DirectX Tutorial"
  103.             If Fullscreen_Enabled = True Then .FormBorderStyle = Windows.Forms.FormBorderStyle.None
  104.         End With
  105.  
  106.         DirectX9_Initialize()
  107.  
  108.     End Sub
  109.  
  110.     Private Sub Shutdown()
  111.  
  112.         Running = False
  113.         Direct3D_Device = Nothing
  114.         Application.Exit()
  115.  
  116.     End Sub
  117.  
  118.     Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
  119.  
  120.         If e.KeyCode = Keys.Escape Then Shutdown()
  121.  
  122.     End Sub
  123.  
  124.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  125.  
  126.         Main()
  127.  
  128.     End Sub
  129.  
  130.     Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
  131.  
  132.         Shutdown()
  133.  
  134.     End Sub
  135.  
  136.     Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
  137.  
  138.         Game_Loop()
  139.  
  140.     End Sub
  141. End Class