Basta executar a SUB DrawGradient, passando os seguintes valores:
lDestHDC - O hDC do objeto que você deseja desenhar alDestWidth - A largura da GradientelDestHeight - A altura da GradientelStartColor - A cor do gradiente começa comlEndColor - A cor do gradiente termina comiStyle - 0 para a esquerda para a direita ou gradiente de 1 para cima para baixo gradiente.Crie um novo módulo e insira este código:
No evento de leitura do Form coloque este código (Set Autoredraw to true to reduce flickering while resizing the form.)Type RECTLeft As LongTop As LongRight As LongBottom As LongEnd TypeDeclare Function CreateSolidBrush Lib "gdi32" _(ByVal crColor As Long) As LongDeclare Function DeleteObject Lib "gdi32" _(ByVal hObject As Long) As LongDeclare Function FillRect Lib "user32" _(ByVal hDC As Long, lpRect As RECT, _ByVal hBrush As Long) As LongPublic Sub DrawGradient (lDestHDC As Long, _lDestWidth As Long, lDestHeight As Long, _lStartColor As Long, lEndColor As Long, _iStyle As Integer)Dim udtRect As RECTDim iBlueStart As IntegerDim iBlueEnd As IntegerDim iRedStart As IntegerDim iRedEnd As IntegerDim iGreenStart As IntegerDim iGreenEnd As IntegerDim hBrush As LongOn Error Resume Next'Calculate the beginning colorsLet iBlueStart = Int(lStartColor / &H10000)Let iGreenStart = Int(lStartColor - (iBlueStart * &H10000)) \ CLng(&H100)Let iRedStart = lStartColor - (iBlueStart * &H10000) - CLng(iGreenStart * CLng(&H100))'Calculate the End colorsLet iBlueEnd = Int(lEndColor / &H10000)Let iGreenEnd = Int(lEndColor - (iBlueEnd * &H10000)) \ CLng(&H100)Let iRedEnd = lEndColor - (iBlueEnd * &H10000) - CLng(iGreenEnd * CLng(&H100))Const intBANDWIDTH = 1Dim sngBlueCur As SingleDim sngBlueStep As SingleDim sngGreenCur As SingleDim sngGreenStep As SingleDim sngRedCur As SingleDim sngRedStep As SingleDim iHeight As IntegerDim iWidth As IntegerDim intY As IntegerDim iDrawEnd As IntegerDim lReturn As LongLet iHeight = lDestHeightLet iWidth = lDestWidthLet sngBlueCur = iBlueStartLet sngGreenCur = iGreenStartLet sngRedCur = iRedStart'Calculate the size of the color barsIf iStyle = 0 ThensngBlueStep = intBANDWIDTH * _(iBlueEnd - iBlueStart) / (iWidth - 60) * 15sngGreenStep = intBANDWIDTH * _(iGreenEnd - iGreenStart) / (iWidth - 60) * 15sngRedStep = intBANDWIDTH * _(iRedEnd - iRedStart) / (iWidth - 60) * 15With udtRectLet .Left = 0Let .Top = 0Let .Right = intBANDWIDTH + 2Let .Bottom = iHeight / 15 - 2End WithLet iDrawEnd = iWidthElseIf iStyle = 1 ThenLet sngBlueStep = intBANDWIDTH * _(iBlueEnd - iBlueStart) / (iHeight - 60) * 15Let sngGreenStep = intBANDWIDTH * _(iGreenEnd - iGreenStart) / (iHeight - 60) * 15Let sngRedStep = intBANDWIDTH * _(iRedEnd - iRedStart) / (iHeight - 60) * 15With udtRectLet .Left = 0Let .Top = 0Let .Right = iWidth / 15 - 2Let .Bottom = intBANDWIDTH + 2End WithLet iDrawEnd = iHeightEnd If'Draw the GradientFor intY = 0 To (iDrawEnd / 15) - 5 Step intBANDWIDTHLet hBrush = CreateSolidBrush(RGB(sngRedCur, sngGreenCur, sngBlueCur))Let lReturn = FillRect(lDestHDC, udtRect, hBrush)Let lReturn = DeleteObject(hBrush)Let sngBlueCur = sngBlueCur + sngBlueStepLet sngGreenCur = sngGreenCur + sngGreenStepLet sngRedCur = sngRedCur + sngRedStepIf iStyle = 0 ThenLet udtRect.Left = udtRect.Left + intBANDWIDTHLet udtRect.Right = udtRect.Right + intBANDWIDTHElseIf iStyle = 1 ThenLet udtRect.Top = udtRect.Top + intBANDWIDTHLet udtRect.Bottom = udtRect.Bottom + intBANDWIDTHEnd IfNextEnd Sub'--end code block
No evento de resize do Form coloque este códigoLet Me.AutoRedraw = TrueDrawGradient Me.hDC, Me.Width, Me.Height, vbBlue, vbRed, 0'--end code block
ClsDrawGradient Me.hDC, Me.Width, Me.Height, vbBlue, vbRed, 0'--end code block
References:
Tags: VBA, Tips, gradient, gradiente
Tags: VBA, Tips, gradient, gradiente
Nenhum comentário:
Postar um comentário