65.9K
CodeProject is changing. Read more.
Home

Draw to Screen without using API

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Jun 22, 2011

CPOL
viewsIcon

13859

Draw to Screen without using API

I like GDI+ very much and today I was playing with some code and luckily I found out how to draw to my computer screen without using any API support. Hope the code may help someone ....
Public Class Form1
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)
        Dim rect As Rectangle = New Rectangle(0, 0, 100, 100)
        Rect.Inflate(2, 2)
        Using g As Graphics = Graphics.FromHwnd(IntPtr.Zero)
            Using lgb As New Drawing2D.LinearGradientBrush(rect, Color.Red, Color.Orange, 90, True)
                g.FillRectangle(lgb, rect)
                g.DrawString(Me.Text, Me.Font, Brushes.White, rect)
            End Using
        End Using
    End Sub
End Class