Lazarus

Free Pascal => Beginners => Topic started by: JLWest on November 22, 2020, 05:31:18 am

Title: {Solved)TCanvas Question
Post by: JLWest 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.
Title: Re: TCanvas Question
Post by: lucamar 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.
Title: Re: TCanvas Question
Post by: JLWest 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.
Title: Re: TCanvas Question
Post by: lucamar 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.
Title: Re: TCanvas Question
Post by: JLWest 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.

Title: Re: TCanvas Question
Post by: dbannon 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
Title: Re: TCanvas Question
Post by: wp 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).
Title: Re: TCanvas Question
Post by: JLWest on November 22, 2020, 04:53:38 pm
@dbanon

 The light blue was perfect.

Thanks all
Title: Re: TCanvas Question
Post by: winni 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
Title: Re: TCanvas Question
Post by: JLWest 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.

TinyPortal © 2005-2018