我基本上希望表单中的矩形显示彩虹渐变并对其进行动画处理(向右移动),最好将其作为背景,以便在顶部显示透明图片。
我尝试将彩虹gif作为背景动画,但是gif永远不会像代码生成的光谱那样明亮。
我还设法实现了一个移动梯度的随机代码,但这使梯度来回移动。
'''
Private Sub picCanvas_Paint(ByVal sender As Object, ByVal e _
As PaintEventArgs) Handles _
WallpaperPreview.Paint
' Draw the background gradient.
Dim br As New LinearGradientBrush(New Point(0, 0), New _
Point(Me.ClientSize.Width, 0), Color.Red,
Color.Blue)
Dim color_blend As New ColorBlend
color_blend.Colors = New Color() {Color.Red,
Color.White, Color.Blue}
color_blend.Positions = New Single() {0, m_Middle, 1}
br.InterpolationColors = color_blend
e.Graphics.FillRectangle(br, Me.ClientRectangle)
br.Dispose()
' Change the gradient's midpoint.
m_Middle += m_Delta
If (m_Middle > 1) OrElse (m_Middle < 0) Then m_Delta =
-m_Delta
End Sub
'''
是否可以将其转换为始终正确移动的彩虹渐变?
编辑: 我的解决办法是这样
'''
Private posX As Single = 0
Private posXmover As Single = 10
Private Sub Timer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer.Tick
WallpaperPreview.Invalidate()
End Sub
Private Sub WallpaperPreview_Paint(ByVal sender As Object, ByVal e _
As PaintEventArgs) Handles _
WallpaperPreview.Paint
Dim rect As New Rectangle(posX, 0,
WallpaperPreview.ClientSize.Width * 2,
WallpaperPreview.ClientSize.Height)
Dim br As New LinearGradientBrush(rect, Color.Red,
Color.Blue, 0)
Dim color_blend As New ColorBlend
color_blend.Colors = New Color() {
Color.Red,
Color.Magenta,
Color.Blue,
Color.Cyan,
Color.Green,
Color.Yellow,
Color.Red,
Color.Magenta,
Color.Blue,
Color.Cyan,
Color.Green,
Color.Yellow,
Color.Red}
color_blend.Positions = New Single() {0, 0.083F, 0.163F, 0.249F, 0.332F, 0.415F, 0.5F, 0.583F, 0.66F, 0.749F, 0.832F, 0.915F, 1}
br.InterpolationColors = color_blend
e.Graphics.Clear(WallpaperPreview.BackColor)
e.Graphics.FillRectangle(br, Me.ClientRectangle)
br.Dispose()
posX += posXmover
End Sub
'''