Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / VB

Draw to Screen without using API

5.00/5 (2 votes)
25 Jun 2011CPOL 13.9K  
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 ....

VB
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)