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:
- Learn Binary Numbering System
- Learn Binary Numbering System-2
- Octal Numbering System
- Hexadecimal Numbering System
- 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.
Now, open the VBA Editing Window (Alt+F11) and display the Debug window (Ctrl+G)
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.
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.
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.
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.
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.
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.
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.
The Text Box with the Label RGB Color displays the RGB Color Number.
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.
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.
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:
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.
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.
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.
No comments:
Post a Comment
Comments subject to moderation before publishing.