I am a VB programmer. I have been developing database applications. After a long time, I feel bored and want to change my taste, but I have no time to learn and materials, I happened to see the learning experience written by others on CSDN, so I quickly entered the door. Good things are not exclusive. As I learned, I changed the original C # program to vb.net code, but the idea is the same and it is only for your reference.
Imports Microsoft. DirectX
Imports Microsoft. DirectX. Direct3D
Public Class Form1
Inherits System. Windows. Forms. Form
# Region "code generated by Windows Form Designer"
Public Sub New ()
MyBase. New ()
This call is required by the Windows Form Designer.
InitializeComponent ()
Add any initialization after InitializeComponent () is called
Me. SetStyle (ControlStyles. AllPaintingInWmPaint Or ControlStyles. Opaque, True)
End Sub
Form override dispose to clear the component list.
Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
Components. Dispose ()
End If
End If
MyBase. Dispose (disposing)
End Sub
Required by the Windows Form Designer
Private components As System. ComponentModel. IContainer
Note: The following procedure is required by the Windows Forms designer
You can use the Windows Form Designer to modify this process.
Do not use the code editor to modify it.
<System. Diagnostics. DebuggerStepThrough ()> Private Sub InitializeComponent ()
Form1
Me. AutoScaleBaseSize = New System. Drawing. Size (6, 14)
Me. ClientSize = New System. Drawing. Size (292,266)
Me. Name = "Form1"
Me. Text = "Form1"
End Sub
# End Region
AYou posted on
Private device As Device
Public Sub InitializeGraphics ()
Set parameters
Dim presentParams As PresentParameters = New PresentParameters
PresentParams. receivwed = True window mode
PresentParams. SwapEffect = SwapEffect. Discard exchange
Create a device
Device = New Device (0, DeviceType. Hardware, Me, CreateFlags. SoftwareVertexProcessing, presentParams)
End Sub
Private Sub Form1_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load
InitializeGraphics ()
End Sub
Protected Overrides Sub OnPaint (ByVal e As System. Windows. Forms. PaintEventArgs)
Device. Clear (ClearFlags. Target, System. Drawing. Color. CadetBlue, 1.0F, 0)
Dim verts (2) As CustomVertex. TransformedColored
Verts (0). Position = New Vector4 (Me. Width/2.0F, 50366f, 0.5F, 1.0F)
Verts (0). Color = System. Drawing. Color. Aqua. ToArgb ()
Verts (1). Position = New Vector4 (Me. Width-Me. Width/5.0F, Me. Height-Me. Height/5.0F, 0.5F, 1.0F)
Verts (1). Color = System. Drawing. Color. Black. ToArgb ()
Verts (2). Position = New Vector4 (Me. Width/5.0F, Me. Height-Me. Height/5.0F, 0.5F, 1.0F)
Verts (2). Color = System. Drawing. Color. Purple. ToArgb ()
Device. BeginScene ()
Device. VertexFormat = CustomVertex. TransformedColored. Format
Device. DrawUserPrimitives (PrimitiveType. TriangleList, 1, verts)
Device. EndScene ()
Device. Present ()
Me. Invalidate ()
End Sub
End Class