Recent

Author Topic: [Graphic] Why the color of image component become black?  (Read 33241 times)

brant_chen

  • New Member
  • *
  • Posts: 14
    • BrantC
[Graphic] Why the color of image component become black?
« on: March 26, 2011, 07:15:47 am »
I use default settings for my Image component.
Once I add code to mouseclick event of image component, the background color become black.
Why?

Code: [Select]
procedure Tf_main.Image1Click(Sender: TObject);
begin
  Image1.Canvas.Pen.Color:=clRed;
  Image1.Canvas.Line(1,1,800,600);
end;

With above code, when launching program, the background color of image1 is clWindows, once I click on it, it become black and draw a line in Red.
How could I do to prevent changing the background? Where does the black come?
Thank you.
简单,快乐,就好。

brant_chen

  • New Member
  • *
  • Posts: 14
    • BrantC
Re: [Graphic] Why the color of image component become black?
« Reply #1 on: March 26, 2011, 08:07:39 am »
ok, I find the answer by myself.

The default brush color for image component is clblack.
I need set it to clWindow or any other, then, I need fillrect for image component, like below:
Code: [Select]

  Image1.Canvas.Brush.Color:=clgreen;
  Image1.Canvas.FillRect(image1.BoundsRect);         
简单,快乐,就好。

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: [Graphic] Why the color of image component become black?
« Reply #2 on: March 26, 2011, 12:10:43 pm »
There is:

Code: [Select]
Image.Canvas.Clear;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

brant_chen

  • New Member
  • *
  • Posts: 14
    • BrantC
Re: [Graphic] Why the color of image component become black?
« Reply #3 on: March 26, 2011, 01:39:44 pm »
There is:

Code: [Select]
Image.Canvas.Clear;

Thank you :)
It's a good habit clearing canvas before you do a dozen of whole new things.
简单,快乐,就好。

 

TinyPortal © 2005-2018