Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleFill an ellipse with a color gradient
DescriptionThis example shows how to fill an ellipse with a color gradient in Visual Basic .NET.
Keywordsellipse, color, color gradient, LinearGradientBrush, fill, VB.NET
CategoriesGraphics, VB.NET
 
Make two Point objects that define where you want the color gradient to start and end. In this example, that's the top and bottom of the ellipse. Use the points to create a new LinearGradientBrush and use it to fill the ellipse.
 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.Clear(Me.BackColor)

    Dim rect As New Rectangle(20, 20, Me.ClientSize.Width - _
        40, Me.ClientSize.Height - 40)

    ' Make a gradient brush.
    Dim pt1 As New Point(rect.Left + rect.Width \ 2, _
        rect.Top)
    Dim pt2 As New Point(pt1.X, rect.Bottom)
    Using br As New LinearGradientBrush(pt1, pt2, _
        Color.Red, Color.Blue)
        e.Graphics.FillEllipse(br, rect)
    End Using
    e.Graphics.DrawEllipse(Pens.Black, rect)
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated