TextOut





VB.Net


Imports System.Runtime.InteropServices

Public Class Form1

    <DllImport("gdi32")>
    Private Shared Function TextOut(ByVal hdc As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal textstring As String, ByVal charCount As Integer) As Boolean
    End Function

    Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        Dim g As Graphics = Graphics.FromHwnd(TextBox1.Handle)
        Dim hdc As IntPtr = g.GetHdc()
        Dim rect As New Rectangle(10, 10, 100, 20)
        Dim text As String = "Hello World!"

        ' Set the font and text color
        Dim font As New Font("Arial", 12)
        Dim brush As New SolidBrush(Color.Black)

        ' Get the device context handle
        Dim dc As Graphics = Graphics.FromHdc(hdc)

        ' Draw the text
        dc.DrawString(text, font, brush, rect)

        ' Release the device context handle
        g.ReleaseHdc(hdc)

        ' Call TEXTOUT to draw the text on the device context
        TextOut(hdc, rect.X, rect.Y, text & vbNullChar, Len(text))
    End Sub
End Class