Recent

Author Topic: {Solved)TCanvas Question  (Read 1457 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
{Solved)TCanvas Question
« on: November 22, 2020, 05:31:18 am »
I have a box on a form and would the color something different that the standard colors.

Is this doable.
« Last Edit: November 30, 2020, 02:11:36 am by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TCanvas Question
« Reply #1 on: November 22, 2020, 05:49:43 am »
Do you mean something like a TGroupBox or alike? Then yes, with some caveats: it might work if you just change its Color (and Font.Color) property to whatever you want, but the borders will still be drawn by the system and colored according to the theme and the same might happen with the controls inside, depending on the control.

If that doesn't work then you might be able to do it in a handler for its OnPaint event ... if the control has it! Which TGroupBox, for example, haven't.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: TCanvas Question
« Reply #2 on: November 22, 2020, 06:04:38 am »
Year in an onPaint event. It a box drawn in the onpaint event and then some buttons in the box/ I woul like the background a different color tjat the dark colors of the pallet.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TCanvas Question
« Reply #3 on: November 22, 2020, 07:05:50 am »
So you're drawing the box by yourself already? Then just set the color of its brush/pen to whatever you want, like:
Code: Pascal  [Select][+][-]
  1. BoxCanvas.Brush.Color := clWhite; {or whatever color you want}
if you're using, say, MyCanvas.FillRect() to draw it.
« Last Edit: November 22, 2020, 07:08:04 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: TCanvas Question
« Reply #4 on: November 22, 2020, 08:30:26 am »
@Lucamar - Hope your  doing good - staying safe.

Thanks for the reply.
Yea, that's the way I'm doing it now. But all of those colors are really dark heavy colors. I'm looking for something like the CLlime but way lighter, just a light shade of lime.

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: TCanvas Question
« Reply #5 on: November 22, 2020, 12:36:25 pm »
BoxCanvas.Brush.Color := $FFFFDD;   // pale blue

Its RRGGBB as hex numbers, $FFFFFF is all black, $000000 is all white.  Just experiment a bit to get the colour you want.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: TCanvas Question
« Reply #6 on: November 22, 2020, 01:03:19 pm »
Its RRGGBB as hex numbers ...
Hex numbers - correct. But be careful with the byte order: I always remember (and I checked it again) that red is 255, i.e. $0000FF. Therefore the order of bytes in this hex number is $BBGGRR (opposite to html).

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: TCanvas Question
« Reply #7 on: November 22, 2020, 04:53:38 pm »
@dbanon

 The light blue was perfect.

Thanks all
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: TCanvas Question
« Reply #8 on: November 22, 2020, 06:50:09 pm »
Hi!

If you want  to learn about colors you can play around with:

Code: Pascal  [Select][+][-]
  1. var red, green, blue : byte;
  2. Color : TColor;
  3. HexString: string;
  4.  
  5. .....
  6. // Get the 3 channel colors from TColor
  7. RedGreenBlue(Color,red,green,blue);    
  8.  
  9. // Build TColor from the 3 colors
  10. Color := RGBToColor(red, green, blue);
  11.  
  12. // Get the HexString from a color
  13. HexString := '$'+HexStr(Color,6);  
  14.  

Winni

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: TCanvas Question
« Reply #9 on: November 24, 2020, 01:59:52 am »
@winni

 Thank you

 I was thinking about something like this that would be a neat utility.

 It would basically go thru all the valid hex numbers for colors and display the color on the  form.

 Maybe you have a selection of the basic color pallet. Click on one and it steps thru the colors showing each color and the hex value.

Now that I have writen it out it looks a little   complicated.

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018