将Windows窗体背景颜色设置为混合颜色?

时间:2016-03-18 13:28:38

标签: vb.net winforms

Visual Basic非常新,我需要将Windows窗体的背景颜色设置为Dim col As New ColorBlend Dim myColours As Color() = {Color.Red, Color.Green} col.Colors = myColours Me.BackColor 这是我到目前为止所拥有的。我该如何完成它?

testng.classNames

我知道这可能看起来有点徒劳,但我需要它来完成任务。谢谢

1 个答案:

答案 0 :(得分:0)

下面的代码非常适合我:

    Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)
        'Define starters (the point [0,0] is the top-left corner of the form)
        Dim y As Integer = 0
        Dim x As Integer = 0
        'Define the dimension (here it depends on your form dimension)
        Dim wid As Integer = Me.Width
        Dim hgt As Integer = Me.Height

        Dim red_green_brush As New LinearGradientBrush(New Point(x, y), New Point(x + wid, y), Color.Red, Color.Green)
        ' ColorBlend.
        pevent.Graphics.DrawString("ColorBlend", Me.Font, Brushes.Red, x, y)
        y += 15
        Dim color_blend As New ColorBlend(2)
        color_blend.Colors = New Color() {Color.Red, Color.Green}
        color_blend.Positions = New Single() {0.0, 1.0}
        red_green_brush.InterpolationColors = color_blend
        pevent.Graphics.FillRectangle(red_green_brush, x, y, wid, hgt)
        red_green_brush.Dispose()
    End Sub