让一个图形控件背景色由一种色到别一种色渐变.怎样实现?
解决方案 »
- MFC 中如何控制toolbar上的按钮是否可用
- 怎样取得在本机上安装的所有软件列表
- 关于listview的一个显示方面的问题?
- pos机上的打印问题!
- VB6.0+Access2000下SQL语句如何写
- 我是VB新手。我想知道如何设置Timer控件的值,使它1分钟激活一次。谢谢
- 关于VB的F1联机帮助的问题
- dim a as string*16 如何去掉空格
- 怎么样通过VB读office中的outlook导出的*.psd文件信息?
- listbox 怎么实现自动换行???textbox 怎样实现添加一行???
- 怎样在MSHFlexGrid里的text里 再回车时能够跳到下一个单元格里 ,在一行结束是跳到下一行 该怎样做。。请各位指点。
- vb怎么取得硬盘的信息???就是不管重新安装系统,格式化什么的都不变的信息
http://www.sijiqing.com/vbgood/article/001192137.html
'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