' Simple WinForm Application to draw an ellipse ' Downloaded from www.publicjoe.co.uk ' ' This software is provided 'as-is', without any express or implied warranty. ' In no event will the author(s) be held liable for any damages arising from ' the use of this software. ' ' Permission is granted to anyone to use this software for any purpose, ' including commercial applications, and to alter it and redistribute it ' freely. Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.Drawing.Drawing2D Public Class PathDemo : Inherits Form 'Run the application Public Shared Sub Main() Application.Run(New PathDemo( )) End Sub Public Sub New() MyBase.New() Me.Text = "Path Demo 2" Me.ClientSize = New Size(250, 200) End Sub Private components As System.ComponentModel.IContainer 'Form overrides dispose to clean up 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 Private Sub PathDemo_Paint( ByVal sender As Object, _ ByVal e As PaintEventArgs) _ Handles MyBase.Paint ' Get Graphics Object Dim g As Graphics = e.Graphics ' Create graphics path object and add ellipse. Dim graphPath As New GraphicsPath() graphPath.AddEllipse(46, 4, 28, 28) graphPath.AddLine(36, 32, 84, 32) graphPath.AddLine(100, 80, 88, 84) graphPath.AddLine(76, 50, 74, 84) graphPath.AddLine(90, 150, 74, 150) graphPath.AddLine(60, 100, 46, 150) graphPath.AddLine(32, 150, 46, 84) graphPath.AddLine(44, 50, 32, 84) graphPath.AddLine(20, 80, 36, 32) ' Create Rectangle To Limit brush area. Dim rect As New Rectangle(20, 0, 100, 150) ' Create Brush Dim linearBrush As New LinearGradientBrush( rect, _ Color.Red, _ Color.Yellow, _ LinearGradientMode.BackwardDiagonal) ' Draw path to screen. g.FillPath( linearBrush, graphPath ) ' Now tidy up linearBrush.Dispose() End Sub End Class