Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Create your own color palette

Introduction.

We have learned Binary, Octal & Hexadecimal Number Systems and learned a few simple rules by which we can devise new number systems with any Base value, provided the user knows about it and can decipher the new number. 

Last week we worked with a Form to enter Decimal Numbers and get them converted into Binary as well as to display the RGB Color for that number.

If you would like to learn and understand Binary, Octal, and Hexadecimal Number Systems then check the following Posts:

  1. Learn Binary Numbering System
  2. Learn Binary Numbering System-2
  3. Octal Numbering System
  4. Hexadecimal Numbering System
  5. Colors 24-Bits And Binary Conversion.

This week, we will work with a Form-based Utility that is more useful to you at the design time of a new Project.  You can create your own 24-bit custom colors visually and save up to 15 colors in a Color Palette in the Form. You can pick any of these colors and apply them to the Form background or on other Control's Foreground, Background, or Border Color Properties at design time.

An image of the Employees Form in Design View with the Form's Header Section Property Sheet along with the Color Palette Form is given below for reference:


The Color Palette Usage

New custom color is created on the color palette Form (see the big rectangle) and applied in the Employees Form Header Section Background, by setting the color value in the Back Color Property.

Click on the image to enlarge it.  The Employees Form is in Design View, its Header Section is in the selected state and its Property Sheet with the Back Color Property is visible.  When you click on one of the grids of 15 Color Boxes (these you can create yourself and save it in each box of the color palette, over-writing the existing ones) will display its corresponding color number in the Text Box above the Color Palette with RGB Color label.  You can copy (Ctrl+C) and Paste (Ctrl+V) into the Property Sheet for Value: Back Color, ForeColor, or Border Color, as the case may be, to set the Color of Form Background or Control Colors.

The Color Values in the above Properties will be shown in Hexadecimal Form with a hash symbol like #4E61BC.  But you can paste the Decimal Color Value there and it will automatically convert into Hexadecimal form.  Since we have learned Hexadecimal Number System I want to draw your attention to a small problem.

A Test Run.

Let us take a sample Color Number in Decimal: 12345678 for the Form Header or Detail Section Back Color and paste it (or type it) into the Property Sheet and press Enter key. It will be converted into Hexadecimal Number like #4E61BC and the Form Background will be filled with a Dark Blue Color.  Take note of the first two digits and last two digits of the Hexadecimal Number shown in blue and red colors.

  1. Now, open the VBA Editing Window (Alt+F11) and display the Debug window (Ctrl+G)

  2. Type:  ? HEX(12345678) and press Enter key to convert the Decimal Number 12345678 into Hexadecimal Number. The Question mark is the Print Command. The hexadecimal number output will be BC614E. If you paste this Hexadecimal number into a control's Back Color Property, like #BC614E the color displayed will be Dark-Red.

  3. Instead, if you type the Number 12345678 into the Back Color Property directly the value is automatically converted into Hexadecimal form and inserted as #4E61BC, in RGB Color Format (R=78, G=97, B=188). The number 78 (&h4E) loaded into the Least Significant 8-bit value, 188  (&hBC) will be loaded into the Most Significant 8 Bits, and 97 (&h61) goes into the middle 8 Bit position.

  4. When we convert the value 12345678 into Hexadecimal form and directly paste it into the Back Color Property the value is taken as it is in the same order as it is placed and ends up with a different Color. 

  5. In either case, the Decimal to Hexadecimal conversion takes place as we did in the Decimal to Binary conversion Method-1 explained in the earlier Article.

 The safest method is to Paste the decimal value in the Color Property and let MS-Access take care of the conversion part.

Creating New Colors and Saving it in the Color Palette.

Now, we will look at the simple trick of designing new Colors, (logically there are over 16 Million 24 Bit color values available) and saving them on the Color palette for later use. 

You can download a database with the above Form with the Programs from a link at the bottom of this article so that you can Import this Form into your new Projects, design your own colors and use them on your Forms or Controls.

You can click on the above image to enlarge it to view the controls properly.  Let us examine the controls on the Form.

  1. There are three Scrollbar controls to input the integer values from 0 to 255 Red, Green, and Blue colors (primary colors) by moving the Scrollbar's slider controls.  Move the Scrollbar to the right to increase the value, or left to decrease the value, of each color. If you click on the arrow marks on the right/left edges of the scrollbars then the values will increase by 1 on each click or if you click and hold the edge control, then the value will increase/decrease rapidly and the color graph also will change with it.  You can watch the large rectangle at the bottom right, and how the new color is formed by changing the colors with the Red, Green, and Blue Scrollbars.

  2. The Bar Graph at the right of the scrollbars gives a visual indication of the variation of color values, which mixes together to form the new color, and the decimal values appear in the TextBoxes at the left, with the labels Red, Green, and Blue.

  3. The big rectangle label control, at the bottom right of the Form, displays the new color created by setting the values in the scrollbar control.

  4. The Text Box with the Label RGB Color displays the RGB Color Number.

  5. You can highlight the number in the RGB Color Text Box and Copy (Ctrl+C) the Number and Paste (Ctrl+V) it into the Form's/Control's Back Color, ForeColor, or Border Color Property to set the Color there.

  6. If you would like to preserve this newly created color, then you can click on the big rectangle, to pick the color there, then click on one of the 15 color boxes shown on the left to store that color in that box for later use.

  7. If you want to pick a color from one of the saved colors then click on it.  The selected color number will appear in the RGB Color Text Box above.  You can Copy and Paste it into the Color Property of the Form or Control.

Tips:

  1. You have the RGB Color Number, but if you want to modify it to your liking, then copy and Paste that color decimal number into the RGB Color Text Box (or type it in) and press the Enter Key.  The color will appear in the big rectangle and the Red, Green, and Blue Text Boxes will display their corresponding color values. The Bar Chart will give you a visual clue of each color at a glance.  You may then move the slider of the Scrollbar Controls to modify the color.

  2. If you are using MS-Access2007 then you must convert the Hexadecimal Number into a Decimal Number by typing: ? &hXXxxXX in the Debug Window, where xX stands for Hexadecimal digits. Don't forget to interchange the rightmost two digits with the leftmost two digits of the six-digit hexadecimal number.  You will get the result in Decimal Number form and then you can copy it into the RGB Color Text Box to modify.

  3. You can directly enter integer values (Ranging from 0 to 255) in the Red, Green, and Blue Text Boxes, which are given at the left of the Scrollbar Controls to create a new color.

Technorati Tags:

Download the Demo Database.


Download Demo RGBColor.zip

Share:

No comments:

Post a Comment

Comments subject to moderation before publishing.

Translate

PageRank

MSA GURU : Access Tips & Tricks App

  • Download Android App 'MSA Guru' Version of LEARN MS-ACCESS TIPS AND TRICKS from Google Play Store.

Newsletter


Feed

Subscribe in a reader
Your email address:

Delivered by FeedBurner

Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Android App Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code