让一个图形控件背景色由一种色到别一种色渐变.怎样实现?

解决方案 »

  1.   

    图形控件你必须自己做,至于渐变,可以参考这个文章:
    http://www.sijiqing.com/vbgood/article/001192137.html
      

  2.   

    这里有个窗体背景色渐变的例子,修改一下,可以使图片控件渐变
    'Example by Thomas Gobler ([email protected])
    Option Explicit
    Private Type GRADIENT_TRIANGLE
        Vertex1 As Long
        Vertex2 As Long
        Vertex3 As Long
    End Type
    Private Type TRIVERTEX
        X As Long
        Y As Long
        Red As Integer 'Ushort value
        Green As Integer 'Ushort value
        Blue As Integer 'ushort value
        Alpha As Integer 'ushort
    End Type
    Private Type GRADIENT_RECT
        UpperLeft As Long  'In reality this is a UNSIGNED Long
        LowerRight As Long 'In reality this is a UNSIGNED Long
    End Type
    Const GRADIENT_FILL_RECT_H As Long = &H0 'In this mode, two endpoints describe a rectangle. The rectangle is
    'defined to have a constant color (specified by the TRIVERTEX structure) for the left and right edges. GDI interpolates
    'the color from the top to bottom edge and fills the interior.
    Const GRADIENT_FILL_RECT_V  As Long = &H1 'In this mode, two endpoints describe a rectangle. The rectangle
    ' is defined to have a constant color (specified by the TRIVERTEX structure) for the top and bottom edges. GDI interpolates
    ' the color from the top to bottom edge and fills the interior.
    Const GRADIENT_FILL_TRIANGLE As Long = &H2 'In this mode, an array of TRIVERTEX structures is passed to GDI
    'along with a list of array indexes that describe separate triangles. GDI performs linear interpolation between triangle vertices
    'and fills the interior. Drawing is done directly in 24- and 32-bpp modes. Dithering is performed in 16-, 8.4-, and 1-bpp mode.
    Private Declare Function GradientFillTriangle Lib "msimg32" _
    Alias "GradientFill" (ByVal hDC As Long, pVertex As TRIVERTEX, _
    ByVal dwNumVertex As Long, pMesh As GRADIENT_TRIANGLE, ByVal dwNumMesh As Long, _
    ByVal dwMode As Long) As Long
    Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
    Private Sub Form_Load()
        Dim vert(4) As TRIVERTEX
        Dim gTRi(1) As GRADIENT_TRIANGLE
        ScaleMode = vbPixels
        AutoRedraw = True
        Move Left, Top, 3945, 4230
        vert(0).X = 0
        vert(0).Y = 0
        vert(0).Red = -256
        vert(0).Green = 0&
        vert(0).Blue = 0&
        vert(0).Alpha = 0&
        
        vert(1).X = 255
        vert(1).Y = 0
        vert(1).Red = 0&
        vert(1).Green = -256
        vert(1).Blue = 0&
        vert(1).Alpha = 0&
        
        vert(2).X = 256
        vert(2).Y = 256
        vert(2).Red = 0&
        vert(2).Green = 0&
        vert(2).Blue = -256
        vert(2).Alpha = 0&
        
        vert(3).X = 0
        vert(3).Y = 256
        vert(3).Red = -256
        vert(3).Green = -256
        vert(3).Blue = -256
        vert(3).Alpha = 0&
        
        gTRi(0).Vertex1 = 0
        gTRi(0).Vertex2 = 1
        gTRi(0).Vertex3 = 2
        
        gTRi(1).Vertex1 = 0
        gTRi(1).Vertex2 = 2
        gTRi(1).Vertex3 = 3
        GradientFillTriangle hDC, vert(0), 4, gTRi(0), 2, GRADIENT_FILL_TRIANGLE
        Form1.Show
    End Sub
    Private Function RgbParse(hDC As Long, X As Single, Y As Single) As String
        Dim ColorMe As Long
        ColorMe = GetPixel(hDC, X, Y)
        Dim rgbRed, rgbGreen, rgbBlue As Long
        rgbRed = Abs(ColorMe Mod &H100)
        ColorMe = Abs(ColorMe \ &H100)
        rgbGreen = Abs(ColorMe Mod &H100)
        ColorMe = Abs(ColorMe \ &H100)
        rgbBlue = Abs(ColorMe Mod &H100)
        ColorMe = RGB(rgbRed, rgbGreen, rgbBlue)
        RgbParse = "RGB(" & rgbRed & ", " & rgbGreen & ", " & rgbBlue & ")"
    End Function
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Caption = RgbParse(hDC, X, Y)
    End Sub
      

  3.   

    SafeF8(^_^) :写的这段代码我用了一下,但没懂,不能填满整个窗口或控件。