| Blog Office VBA | Blog Excel | Blog Access |
A apresentação das nossas aplicações é muito importante. Por isso, termos a opção de deixar o fundo dos nossos formulários com um tom gradiente, certamente seria muito apropriado.
A técnica demonstrada abaixo envolve cobrirmos o nosso formulário com uma camada de retângulos, os quais são automaticamente colocados e posicionados por uma funcionalidade. Outra rotina faz a distribuição de cores de acordo com as cores que escolhermos.
Para escolhermos as cores, precisamos estar familiarizados com essa pequena lista das cores do Windows (ID Windows Colors)
ID da Cor Descrição da Cor
----------- -----------------
-2147483648 Scroll bar
-2147483647 Desktop
-2147483646 Active window title bar
-2147483645 Inactive window title bar
-2147483644 Menu bar
-2147483643 Window
-2147483642 Window frame
-2147483641 Menu Text
-2147483640 Window Text (*)
-2147483639 Title bar text
-2147483638 Active window border
-2147483637 Inactive window border
-2147483636 Application background
-2147483635 Highlight
-2147483634 Highlight Text
-2147483633 3-D face (**)
-2147483632 3-D shadow
-2147483631 Dimmed (disabled) text
-2147483630 Button Text
-2147483629 Inactive window title bar text
-2147483628 3-D highlight (***)
-2147483627 3-D dark shadow
-2147483626 3-D light
-2147483625 ToolTip Text
-2147483624 ToolTip background
-2147483621 Active window title bar color2
Voltando ao código, seguem as funcionalidades...Para que a sua combinação de cores não fique exdrúxula, também é importante que tenha compreensão de como as cores são formadas e compostas no ambiente computacional, aprenda mais aqui.
Insira no módulo basColorPicker:
' Original Code by Terry Kreft' Modified by Stephen Lebans' Contact Stephen@lebans.com' Modified by Peter De Baets' Contact Info@PetersSoftware.com
Option Compare DatabaseOption Explicit'*********** Code Start ***********Private Type COLORSTRUClStructSize As Longhwnd As LonghInstance As LongrgbResult As LonglpCustColors As StringFlags As LonglCustData As LonglpfnHook As LonglpTemplateName As StringEnd TypePrivate Const CC_RGBINIT = &H1Private Const CC_FULLOPEN = &H2Private Const CC_PREVENTFULLOPEN = &H4Private Const CC_SHOWHELP = &H8Private Const CC_ENABLEHOOK = &H10Private Const CC_ENABLETEMPLATE = &H20Private Const CC_ENABLETEMPLATEHANDLE = &H40Private Const CC_SOLIDCOLOR = &H80Private Const CC_ANYCOLOR = &H100Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" _(pChoosecolor As COLORSTRUC) As Long
Public Function aDialogColor (prop As Property) As BooleanDim x As Long, CS As COLORSTRUC, CustColor(16) As LongCS.lStructSize = Len(CS)CS.hwnd = hWndAccessAppCS.rgbResult = Nz(prop.Value, 0)CS.Flags = CC_SOLIDCOLOR Or CC_RGBINITCS.lpCustColors = String$(16 * 4, 0)x = ChooseColor(CS)If x = 0 Then' ERROR - use Default Whiteprop = RGB(255, 255, 255) ' WhiteaDialogColor = FalseExit FunctionElse' Normal processingprop = CS.rgbResultEnd IfaDialogColor = TrueEnd Function'*********** Code End ***********' If you want this Function to simply Return' the Value of the Color the user selected' from the Dialog just change the Function' Declaration in modColorPicker to something like:'Public Function DialogColor(ctl As Control) As Long' Remember to add the line of code at the' end of the Function'DialogColor = CS.rgbResult' Then call it from your Form with code like:'***Code Start'Private Sub CmdChooseBackColor_Click()' Pass the TextBox Control to the function'Me.textCtl.BackColor = DialogColor(Me.textCtl)'End SubPublic Function xg_ChooseColor (lngDefaultColor As Long) As LongDim x As Long, CS As COLORSTRUC, CustColor(16) As LongDim lngRtn As LongCS.lStructSize = Len(CS)CS.hwnd = hWndAccessApp'CS.rgbResult = Nz(prop.Value, 0)CS.rgbResult = Nz(lngDefaultColor, 0)CS.Flags = CC_SOLIDCOLOR Or CC_RGBINITCS.lpCustColors = String$(16 * 4, 0)x = ChooseColor(CS)If x = 0 Then' ERROR - use Default White'prop = RGB(255, 255, 255) ' WhitelngRtn = RGB(255, 255, 255) ' White'aDialogColor = FalseExit FunctionElse' Normal processing'prop = CS.rgbResultlngRtn = CS.rgbResultEnd Ifxg_ChooseColor = lngRtnEnd Function'*********** Code End ***********' If you want this Function to simply Return' the Value of the Color the user selected' from the Dialog just change the Function' Declaration in modColorPicker to something like:'Public Function DialogColor(ctl As Control) As Long' Remember to add the line of code at the' end of the Function'DialogColor = CS.rgbResult' Then call it from your Form with code like:'***Code Start'Private Sub CmdChooseBackColor_Click()' Pass the TextBox Control to the function'Me.textCtl.BackColor = DialogColor(Me.textCtl)'End Sub
Insira no módulo basFormBackColorGradient:
Option Compare DatabaseOption Explicit' Back Color Gradient v1.0 for MS Access from Peter's Software'' Adds a detail section back color gradient effect to your MS Access forms
'' This module was created by:'' Peter's Software' 10540 National Blvd #21' Los Angeles, CA 90034' USA' info@peterssoftware.com' http://www.peterssoftware.com'' We do not require that this header be included in any apps you distribute,' but would appreciate credit being given in your documentation.'' Usage:' bcg_CreateRectangles "<MyFormName>", False - Run this from the "Examples" subroutine in this module' (The last parm can be set to "True" for horizontal' rectangles, providing a vertical color gradient)'' bcg_SetColors Me, <Color1>, <Color2> - From your form's OnOpen or OnActivate event procedure' where <Color1> and <Color2> are Windows system color IDs' or MS Access color values.Const mconNamePrefix = "rctGrad"Const SS_SW_HIDE = 0Const SS_SW_SHOW = 5Const COLOR_SCROLLBAR = 0Const COLOR_BACKGROUND = 1Const COLOR_ACTIVECAPTION = 2Const COLOR_INACTIVECAPTION = 3Const COLOR_MENU = 4Const COLOR_WINDOW = 5Const COLOR_WINDOWFRAME = 6Const COLOR_MENUTEXT = 7Const COLOR_WINDOWTEXT = 8Const COLOR_CAPTIONTEXT = 9Const COLOR_ACTIVEBORDER = 10Const COLOR_INACTIVEBORDER = 11Const COLOR_APPWORKSPACE = 12Const COLOR_HIGHLIGHT = 13Const COLOR_HIGHLIGHTTEXT = 14Const COLOR_BTNFACE = 15Const COLOR_BTNSHADOW = 16Const COLOR_GRAYTEXT = 17Const COLOR_BTNTEXT = 18Const COLOR_INACTIVECAPTIONTEXT = 19Const COLOR_BTNHIGHLIGHT = 20Private Declare Function apiGetSysColor Lib "user32" Alias "GetSysColor" (ByVal nIndex As Long) As LongPrivate Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongSub Examples()'* This example adds vertical color gradient rectangles to the form "MyForm".'* To run it, just uncomment the line below, replace "MyForm" with your form name'* and Press F5.bcg_CreateRectangles "MyForm", False'* This example adds horizontal color gradient rectangles to the form "MyForm".'* To run it, just uncomment the line below, replace "MyForm" with your form name'* and Press F5.'bcg_CreateRectangles "MyForm", TrueEnd SubSub bcg_CreateRectangles (strFormName As String, blnHorizontal As Boolean)'* This routine adds a contiguous set of thin rectangles to the detail section of the specified form.'* Setting the blnHorizontal parm to True will create thin horizontal rectangles instead of vertical ones.'* Because this routine changes the form design, it is recommended to make a backup of the form'* before executing this routine.Dim i As IntegerDim s As StringDim intNumOfRectangles As IntegerDim intWidth As IntegerDim intHeight As IntegerDim intLeft As IntegerDim intTop As IntegerDim sngAreaCovered As SingleDim sngAreaToCover As SingleDim frm As FormDim lngRtn As LongDim ctl As ControlDim Finished As BooleanDim strProcName As StringOn Error Resume NextstrProcName = "bcg_CreateRectangles"s = "This routine will update the design of your form: '" & strFormName & "'. " & _"It is recommended that you make a backup of your form first. " & vbCrLf & vbCrLf & _"Do you wish to continue?"If MsgBox(s, vbYesNo) = vbYes Then'*ContinueElseMsgBox "Action cancelled."GoTo Exit_SectionEnd If'* Open form in design modeDoCmd.OpenForm strFormName, acDesign, , , , acNormalIf Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (1): " & Err.Number & " - " & Err.description: Err.Clear: GoTo Exit_SectionSet frm = Forms(strFormName)If Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (2): " & Err.Number & " - " & Err.description: Err.Clear: GoTo Exit_Section'* Hide the form during processinglngRtn = apiShowWindow(frm.hwnd, SS_SW_HIDE)'* Delete any and all controls that begin with our rectangle control name prefixFinished = FalseDo While Not FinishedFinished = TrueFor Each ctl In frm.ControlsIf Left(ctl.name, Len(mconNamePrefix)) = mconNamePrefix ThenDeleteControl frm.name, ctl.nameFinished = FalseExit ForEnd IfNext ctlLoopIf Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (3): " & Err.Number & " - " & Err.description: Err.Clear: GoTo Exit_SectionIf blnHorizontal ThenintWidth = frm.WidthintHeight = 1440 / 24sngAreaToCover = frm.Section(acDetail).HeightintLeft = 0ElseintWidth = 1440 / 24intHeight = frm.Section(acDetail).HeightsngAreaToCover = frm.WidthintTop = 0End If'* Create enough rectangle controls to cover the form detail section.sngAreaCovered = 0i = 0Do While sngAreaCovered < sngAreaToCoverIf blnHorizontal ThenintTop = i * (1440 / 24)ElseintLeft = i * (1440 / 24)End If'* Create a rectangle on the formSet ctl = CreateControl(frm.name, acRectangle, acDetail, , , intLeft, intTop, intWidth, intHeight)If Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (4): " & Err.Number & " - " & Err.description: Err.Clear: GoTo Exit_Sectionctl.name = mconNamePrefix & ictl.BackStyle = 1 '* Normalctl.BorderStyle = 0 '* Transparentctl.SpecialEffect = 0 '* Flatctl.Visible = True'* Send rectangle to back so it won't cover other controlsctl.InSelection = TrueDoCmd.RunCommand acCmdSendToBackIf blnHorizontal ThensngAreaCovered = sngAreaCovered + ctl.HeightElsesngAreaCovered = sngAreaCovered + ctl.WidthEnd Ifi = i + 1Loop'* Close the formDoCmd.Close acForm, strFormName, acSaveYesIf Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (5): " & Err.Number & " - " & Err.description: Err.Clear: GoTo Exit_SectionMsgBox "Done. Added color gradient rectangles to form '" & strFormName & "'."Exit_Section:Set ctl = NothingEnd SubSub bcg_SetColors (frm As Form, plngStartingColor As Long, plngEndingColor As Long)'* Loop through all the gradient rectangles on the form and color them.Dim i As IntegerDim intNumOfBoxes As IntegerDim intBoxNo As IntegerDim intTailLength As IntegerDim intStartingRed As IntegerDim intStartingGreen As IntegerDim intStartingBlue As IntegerDim intEndingRed As IntegerDim intEndingGreen As IntegerDim intEndingBlue As IntegerDim intIncrementRed As IntegerDim intIncrementGreen As IntegerDim intIncrementBlue As IntegerDim sngRemainingDiffRed As SingleDim sngRemainingDiffGreen As SingleDim sngRemainingDiffBlue As SingleDim lngStartingColor As LongDim lngEndingColor As LongDim ctl As ControlDim intMax As IntegerDim intThisBoxNo As IntegerDim strProcName As StringOn Error Resume NextstrProcName = "bcg_SetColors"If plngStartingColor < 0 Then'* Get system color using system color idlngStartingColor = apiGetSysColor(bcg_GetColorIndexFromColorID(plngStartingColor))ElselngStartingColor = plngStartingColorEnd IfIf plngEndingColor < 0 Then'* Get system color using system color idlngEndingColor = apiGetSysColor(bcg_GetColorIndexFromColorID(plngEndingColor))ElselngEndingColor = plngEndingColorEnd IfIf Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (1): " & Err.Number & " - " & Err.description: Err.Clear: GoTo Exit_Section'* Find number of boxes (color gradient rectangle controls)intMax = 0For Each ctl In frm.ControlsIf Left(ctl.name, Len(mconNamePrefix)) = mconNamePrefix ThenintThisBoxNo = CInt(Right(ctl.name, Len(ctl.name) - Len(mconNamePrefix)))If intThisBoxNo > intMax ThenintMax = intThisBoxNoEnd IfEnd IfNext ctlIf Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (2): " & Err.Number & " - " & Err.description: Err.Clear: GoTo Exit_SectionIf intMax = 0 Then'* No gradient rectangle controls foundGoTo Exit_SectionEnd IfintNumOfBoxes = intMax + 1'* Compute starting and ending RGB color valuesintStartingRed = GetRGB(lngStartingColor, 1)intStartingGreen = GetRGB(lngStartingColor, 2)intStartingBlue = GetRGB(lngStartingColor, 3)intEndingRed = GetRGB(lngEndingColor, 1)intEndingGreen = GetRGB(lngEndingColor, 2)intEndingBlue = GetRGB(lngEndingColor, 3)'* Find difference between starting and ending valuessngRemainingDiffRed = (intEndingRed - intStartingRed)sngRemainingDiffGreen = (intEndingGreen - intStartingGreen)sngRemainingDiffBlue = (intEndingBlue - intStartingBlue)'* Loop through all gradient rectangle controls and set gradient colors by'* smoothly decrementing the difference between the two colors.For i = 0 To intNumOfBoxes - 1Set ctl = frm(mconNamePrefix & i)If Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (3): " & Err.Number & " - " & Err.description: Err.Clear: Exit Forctl.BackColor = RGB( _intEndingRed - CInt(sngRemainingDiffRed), _intEndingGreen - CInt(sngRemainingDiffGreen), _intEndingBlue - CInt(sngRemainingDiffBlue) _)If Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (4): " & Err.Number & " - " & Err.description: Err.Clear: GoTo Exit_SectionsngRemainingDiffRed = sngRemainingDiffRed - (sngRemainingDiffRed / (intNumOfBoxes - i))sngRemainingDiffGreen = sngRemainingDiffGreen - (sngRemainingDiffGreen / (intNumOfBoxes - i))sngRemainingDiffBlue = sngRemainingDiffBlue - (sngRemainingDiffBlue / (intNumOfBoxes - i))Next ictl.BackColor = RGB( _intEndingRed - CInt(sngRemainingDiffRed), _intEndingGreen - CInt(sngRemainingDiffGreen), _intEndingBlue - CInt(sngRemainingDiffBlue) _)If Err <> 0 Then Beep: MsgBox "Error in " & strProcName & " (5): " & Err.Number & " - " & Err.description: Err.Clear: GoTo Exit_SectionExit_Section:Set ctl = NothingEnd SubFunction bcg_GetColorIndexFromColorID(lngSystemColorID As Long) As Long'* Find the Windows system color index from the Windows system color IDbcg_GetColorIndexFromColorID = lngSystemColorID + 2147483648#End FunctionFunction GetRGB (RGBval As Long, Num As Integer) As Integer'* Returns the Red (Num=1), Green (Num=2), or Blue (Num=3) value for the passed MS Access color value.' Check if Num, RGBval are valid.If Num > 0 And Num < 4 And RGBval > -1 And RGBval < 16777216 ThenGetRGB = RGBval \ 256 ^ (Num - 1) And 255Else' Return True (-1) if Num or RGBval are invalid.GetRGB = TrueEnd IfEnd Function
Tags: VBA, Office, Access, color, color, cor, cores, degradê, gradiente, download
Inspiration:
Download: Download bcg.zip - aplicável no Access 97, Access 2000, Access 2002/XP, Access 2003, Access 2007 e Access 2010
Série de Livros nut Project
Série DONUT PROJECT 2021
Série DONUT PROJECT 2018
Série DONUT PROJECT 2015
Série DONUT PROJECT 2014
Clique aqui e nos contate via What's App para avaliarmos seus projetos
Envie seus comentários e sugestões e compartilhe este artigo!
brazilsalesforceeffectiveness@gmail.com
Nenhum comentário:
Postar um comentário