How to draw Gradient rectangle In Vb.Net?

By James J

Show how to draw gradient rectangle with different different modes...

> For horizontal gradient...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim GradientRectangle As New Rectangle(10, 10, 100, 100)
Using GradientGraphic =
Me.CreateGraphics()
Using
GradientBrush As New LinearGradientBrush(GradientRectangle, Color.Blue, Color.Red, LinearGradientMode.Horizontal)
GradientGraphic.
FillRectangle(GradientBrush, GradientRectangle)
End Using
        
End Using
End Sub

> See below image



> For forward diagonal gradient...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim GradientRectangle As New Rectangle(10, 10, 100, 100)
Using GradientGraphic =
Me.CreateGraphics()
Using
GradientBrush As New LinearGradientBrush(GradientRectangle, Color.Blue, Color.Red, LinearGradientMode.ForwardDiagonal)
GradientGraphic.
FillRectangle(GradientBrush, GradientRectangle)
End Using
        
End Using
End Sub

> See below image





> Like this way the other modes are like below...

>
For backward diagonal gradient...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim GradientRectangle As New Rectangle(10, 10, 100, 100)
Using GradientGraphic =
Me.CreateGraphics()
Using
GradientBrush As New LinearGradientBrush(GradientRectangle, Color.Blue, Color.Red, LinearGradientMode.BackwardDiagonal)
GradientGraphic.
FillRectangle(GradientBrush, GradientRectangle)
End Using
        
End Using
End Sub


> For vertical gradient...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim GradientRectangle As New Rectangle(10, 10, 100, 100)
Using GradientGraphic =
Me.CreateGraphics()
Using
GradientBrush As New LinearGradientBrush(GradientRectangle, Color.Blue, Color.Red, LinearGradientMode.Vertical)
GradientGraphic.
FillRectangle(GradientBrush, GradientRectangle)
End Using
        
End Using
End Sub

How to draw Gradient rectangle In Vb.Net?  (1354 Views)