Jeg har lavet eksemplet i Omens link til VB, og så det gradiere mellem to farver. Det skal ind i et objects paint evenr (eks. en form)
Dim paintObj As Form= CType(sender, Form)
Dim colorA As Color = Color.FromArgb(10, 36, 106) Dim colorB As Color = Color.FromArgb(166, 202, 240)
Dim g As Graphics = e.Graphics
Dim paintPosX As Single
Dim paintColor As Color = colorA
Dim paintR As Single = paintColor.R Dim paintG As Single = paintColor.G Dim paintB As Single = paintColor.B
Dim incrementR As Single = CSng((CInt(colorB.R) - CInt(colorA.R)) / paintObj.Width) Dim incrementG As Single = CSng((CInt(colorB.G) - CInt(colorA.G)) / paintObj.Width) Dim incrementB As Single = CSng((CInt(colorB.B) - CInt(colorA.B)) / paintObj.Width)
For paintPosX = 0 To paintObj.Width paintColor = Color.FromArgb(CInt(paintR), CInt(paintG), CInt(paintB)) g.FillRectangle(New SolidBrush(paintColor), paintPosX, 0, 1, paintObj.Height) paintR += incrementR : paintG += incrementG : paintB += incrementB Next
kinggenesis har ret, men det kan altså gøres smartere.
Public Sub DoPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Dim g As Graphics = e.Graphics g.Clip = New Region(e.ClipRectangle()) Dim br As LinearGradientBrush = New LinearGradientBrush(New Point(0, 0), New Point(Width, Height), Color.DarkBlue, Color.LightBlue) g.FillRectangle(br, e.ClipRectangle) end sub
Bemærk at dette kræver at du importerer system.drawing og system.drawing.drawing2d
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.