Hello.
I've got all the code figured out to make a picture box appear with a gradient inside of it. My problem is that the gradient doesn't appear in the picture box when the form loads, paints, or when the picture box is painted. I can only make the gradient appear if i click the picture box after the form appears.
So what am i doing wrong? It seems like there's a secret step that i'm missing.Code:Dim xFormTopColour As Color = Color.Black Dim xFormBottomColour As Color = Color.DarkOrchid Private Sub frmTestGradientBars3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call GradientPictureBox(xFormTopColour, xFormBottomColour, picSample) End Sub Private Sub frmTestGradientBars3_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Call GradientPictureBox(xFormTopColour, xFormBottomColour, picSample) End Sub Private Sub picSample_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picSample.Paint Call GradientPictureBox(xFormTopColour, xFormBottomColour, picSample) End Sub Private Sub picSample_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picSample.Click Call GradientPictureBox(xFormTopColour, xFormBottomColour, picSample) End Sub Public Sub GradientPictureBox(ByVal xTopColour As Color, ByVal xBottomColour As Color, ByRef picBox As PictureBox) Dim xDirection As Drawing2D.LinearGradientMode = Drawing2D.LinearGradientMode.Vertical 'One of the four directions of the fade Dim xBrush As New Drawing2D.LinearGradientBrush(picBox.DisplayRectangle, xTopColour, xBottomColour, xDirection) Dim xGraphics As Graphics = picBox.CreateGraphics() xGraphics.FillRectangle(xBrush, picBox.DisplayRectangle) xBrush.Dispose() xGraphics.Dispose() End Sub
.




Reply With Quote
