Quantcast
Viewing all articles
Browse latest Browse all 27072

Painting a gradient

Hello!

I have 5 alarm times, morning, noon, afternoon, sunset and night. Now I want my form background to change color depending on what time we are in. If for example it is night at the moment, I will make the color black. If it is sunset, I will make it a gradient between yellow and black etc...

Don't worry about how I'm going to know if it is morning or night. My problem is that I am using this code to paint a gradient on my form:


Code:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
    End Sub

Code:

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim formGraphics As Graphics = e.Graphics
        Dim gradientBrush As New LinearGradientBrush(New Point(5, 0), New Point(Width, 5), Color.DeepSkyBlue, Color.DarkGoldenrod)

        formGraphics.FillRectangle(gradientBrush, ClientRectangle)
    End Sub


Now this code snippet has 2 problems:

1. I cannot call the OnPaint sub. It is automatic right now. It paints the form whenever I start the application. If I later need to change the colors of the gradient, I will have to call this Sub, but I cannot call the sub because it has the parameters (ByVal e As System.Windows.Forms.PaintEventArgs).

2. The gradient is from right to left. I want it to be from top to bottom.

Can anyone please help me?

Viewing all articles
Browse latest Browse all 27072

Trending Articles