Posted on 13th Jun 2019 in Delphi VCL
The Last in the series Part Four covers the following areas.
Progress bar single to multi-color
The progressbar procedure has the option of selecting up to 5 different colors. The procedure has many default settings which can easily be overridden to create a custom looking progressbar.
The standard settings allows maximum of 5 colors in its settings but can be easily adjusted to the minimum of one color.
The procedure has an overduebreakpoint and various breakpoint positions where the color of the progressbar will change color.
If no changes are added during usage then the defaults are automatically used.
In the procedure there are many adjustable settings that can be made which influence how the bar is visualised at run time. With few changes, a custom styled progress bar can be created.
procedure Progressdrawcolumncell(sender:Tobject;grid:Tdbgrid; colpos,datacol,progressvalue: integer; Rect:Trect;column:Tcolumn;State: TGridDrawState; progressnumber:integer = 5; overduebreakpoint:integer = 1; breakpoint1:integer = 65; breakpoint2:integer = 40; breakpoint3:integer = 20; backgroundcolor:TColor = clgray; overduecolor:Tcolor=clwebFirebrick; Color1:Tcolor = clWebLightSkyBlue; Color2:Tcolor = clweborange; Color3:TColor = clWebGold; color4:Tcolor = clWebTomato; maxvalue:integer = 100; progresspadding:integer = 0; isbackground:boolean= false; showtext:boolean = true; Percentge:string = '%');
The code for this procedure is many lines and can be found in the full code download.
Horizontal Stack Bar multi-colors
This is a stacked bar with up to five different colors. To initiate the colors, the formOncreate event is used to activate the bar. It uses a shape to draw each bar. Select the color that the shape must take and a stacked bar is formed.
ColorhorizontalBarshape(shape1,clWebLightSkyBlue); ColorhorizontalBarshape(shape2,clWebLightSeaGreen); ColorhorizontalBarshape(shape3,clweborange); ColorhorizontalBarshape(shape4,clWebGold); ColorhorizontalBarshape(shape5,clWebTomato);
procedure ColorhorizontalBarshape(shape:Tshape;color:Tcolor); begin shape.Brush.Color:= color; shape.Pen.Style:= psClear; end;
The stack Bar is drawn in the DBgrid onDrawColumncell event. Progress values for each shape must be added. The example uses random numbers to populate the chart, numbers from a Database can easily be incorporated into the chart. The maximum bars that can be added are five and minimum bar requirement is one.
The percentage can be changed from %e to any string item. Be aware that the bar would look best with a $ sign for value but the bar would become crowded if a long string name were used. There is the ability to not show any indicators in the bar.
procedure HorizontalBardrawcolumncell(sender:Tobject;grid:Tdbgrid; colpos,datacol,progressvalue1,progressvalue2,progressvalue3,progressvalue4, progressvalue5: integer; Rect:Trect;column:Tcolumn;State: TGridDrawState; progressnumber:integer = 5; //min 1 Color1:Tcolor = clWebLightSkyBlue; Color2:Tcolor = clWebLightSeaGreen; Color3:TColor = clweborange; color4:Tcolor = clWebGold; color5:Tcolor = clWebTomato; maxvalue:integer = 100; progresspadding:integer = 0; isbackground:boolean= false; showtext:boolean = true; Percentge:string = '%');
The lengthy code for this can be viewed in the example download.
Feel Free to download the code that covers all four parts here
June 2019Delphi A Professional VCL DBGrid Part Four
May 2019Delphi A Professional VCL DBGrid Part Three
April 2019Delphi A Professional VCL DBGrid Part Two
March 2019Delphi A Professional VCL DBGrid Part One
November 2018Delphi VCL Buttons in DBGrid
October 2018Two Helper Apps for Delphi LibUSB
September 2018Delphi Libusb Library Introduction
August 2018Delphi Object directly to a Json string in a REST Client
July 2018Delphi FMX Leaflet Plotter using OSM Maps
June 2018C2PAS32 Convertor Application
May 2018Delphi PDF Embedded viewer with PDF.js
March 2018Delphi FMX - Changing TCharacter to TCharHelper
January 2018Delphi FMX Dashboard using Chart.JS
December 2017PHP Slim REST Server & Delphi Auth Part 5
November 2017Delphi FMX REST Client App Part 4
October 2017Delphi VCL REST Pricing Client App Part 3
September 2017Delphi REST VCL Client Basic Auth Part 2B
August 2017Delphi REST Client Part 2A
July 2017PHP REST Server and Delphi Client Intro
June 2017Delphi SQLite Encryptor-Decryptor Tool
May 2017Create a Visual IP Address Geolocation with PHP
March 2017PHP Downloader using Countdown timer
January 2017Morris Charts and PHP-PDO
December 2016CSS to create a functional Toggle Button