Public Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As IntPtr
Public Declare Function GetDCEx Lib "user32" Alias "GetDCEx" (ByVal hwnd As IntPtr, ByVal hrgnclip As IntPtr, ByVal fdwOptions As Integer) As IntPtr
'下面是画模块
Dim WithEvents TestGroupBox As New GroupBox
Private Sub TestGroupBox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles TestGroupBox.Paint
e.Graphics.Clear(TestGroupBox.BackColor)
e.Graphics.DrawString(TestGroupBox.Text, TestGroupBox.Font, Brushes.Red, 10, 1)
Dim a, b, c, d As Integer
a = TextBox2.Left
b = TextBox2.Top
c = TextBox2.Width
d = TextBox2.Height
TextBox2.Text = a & "-" & b & "-" & c & "-" & d
e.Graphics.DrawLine(Pens.Blue, a, b, a + c, b)
e.Graphics.DrawLine(Pens.Blue, a, b, a, b + d)
e.Graphics.DrawLine(Pens.Blue, a + c, b, a + c, b + d)
e.Graphics.DrawLine(Pens.Blue, a, b + d, a + c, b + d)
End Sub
'画图代码
Dim desk As Integer = GetDesktopWindow()
Dim deskDC As Integer = GetDCEx(desk, IntPtr.Zero, &H403)
Dim g As Graphics = Graphics.FromHdc(deskDC)
g.FillEllipse(SystemBrushes.ControlText, 0, 0, 100, 100)
g.Dispose()