BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TPaintBox Like a legend

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
alfio alessi
Guest





PostPosted: Tue Sep 14, 2004 1:32 pm    Post subject: TPaintBox Like a legend Reply with quote



With this code:
procedure TForm1.Button1Click(Sender: TObject);
type
TCatNum = record //category details
Count: Integer;
Descr: String;
Color: TColor;
end;
const
X = 10;
var
I: Integer;
Y: Integer;
CNList: array[0..4] of TCatNum; //ovviamente uso un array dinamico ma
come
esempio penso possa andare bene
begin
TCatNum(CNList[0]).Count := 5;
TCatNum(CNList[0]).Descr := 'Shining';
TCatNum(CNList[0]).Color := clYellow;

TCatNum(CNList[1]).Count := 56;
TCatNum(CNList[1]).Descr := 'Middle';
TCatNum(CNList[1]).Color := $004080FF;

TCatNum(CNList[2]).Count := 65;
TCatNum(CNList[2]).Descr := 'Classic';
TCatNum(CNList[2]).Color := clRed;

TCatNum(CNList[3]).Count := 145;
TCatNum(CNList[3]).Descr := 'Strong';
TCatNum(CNList[3]).Color := clBlue;

TCatNum(CNList[4]).Count := 11;
TCatNum(CNList[4]).Descr := 'Professional';
TCatNum(CNList[4]).Color := clGreen;

Y := 5;
with PaintBox1.Canvas do
begin
Pen.Color := clBlack;
Pen.Style := psSolid;
for I := Low(CNList) to High(CNList) do
begin


{########################################################################}He
re Iwant to put the code the modify the Y variable but after most tentativei
didn't found nothing
{########################################################################}
Brush.Color := TCatNum(CNList[I]).Color;
Rectangle(X, Y, X * 4, Y * 4);
Brush.Color := Self..Color;
TextOut(X * 4 + 2, Y + 1, Format('%s: %d',
TCatNum(CNList[I]).Descr,
TCatNum(CNList[I]).Count]));
end;
end;
end;

Hi,sorry 4 my bad and little english:I want generate a legend but I'm unable
to do it, somebody can help me please??greetings:
Alfio


Back to top
Joris Van Damme
Guest





PostPosted: Tue Sep 14, 2004 2:17 pm    Post subject: Re: TPaintBox Like a legend Reply with quote



Quote:
procedure TForm1.Button1Click(Sender: TObject);
...
with PaintBox1.Canvas do
begin

You shouldn't paint a canvas when you feel like it, e.g. in a Button OnClick
handler, but when you are asked to do so, in the OnPaint handler, instead.

Quote:
re Iwant to put the code the modify the Y variable but after most
tentativei
didn't found nothing

How about Inc(Y,20); or whatever where it says 20.

Joris Van Damme
[email]info (AT) awaresystems (DOT) be[/email]
http://www.awaresystems.be
Download your free TIFF tag viewer for windows here:
http://www.awaresystems.be/imaging/tiff/astifftagviewer.html



Back to top
willem van Deursen
Guest





PostPosted: Tue Sep 14, 2004 2:56 pm    Post subject: Re: TPaintBox Like a legend Reply with quote



Instead of writing to a paintbox you could try to use an ownerdraw
listbox for this. See also the example given with
TCustomListbox.OndrawItem in the Delphi helpfiles.

Place a listbox on your form and add the following code, that should work:

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
BrushColor : TColor;
Offset: Integer;
begin
with (Control as TListBox).Canvas do
begin
BrushColor:=Brush.Color; { save old color }
FillRect(Rect); { clear the rectangle }
Offset := 2; { provide default offset }
Brush.Color:=TColor(integer((Control as
TListBox).Items.Objects[Index])); { Get the color from the Objects-field }

Rectangle(Rect.Left+Offset,Rect.Top+Offset,Rect.Left+Offset+20,Rect.Bottom-Offset);
Offset:=24;
Brush.Color:=BrushColor; { Restore old color }
TextOut(Rect.Left + Offset, Rect.Top, (Control as
TListBox).Items[Index]);
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Style:=lbOwnerDrawFixed;
ListBox1.OnDrawItem:=ListBox1DrawItem;
ListBox1.Items.AddObject(Format('%s: %d',['My first
test',2]),Pointer(Integer(clRed))); {Use the objects field to store the
color }
ListBox1.Items.AddObject(Format('%s: %d',['My second
test',15]),Pointer(Integer(clGreen)));
end;

Success

Willem van Deursen

alfio alessi wrote:

Quote:
With this code:
procedure TForm1.Button1Click(Sender: TObject);
type
TCatNum = record //category details
Count: Integer;
Descr: String;
Color: TColor;
end;
const
X = 10;
var
I: Integer;
Y: Integer;
CNList: array[0..4] of TCatNum; //ovviamente uso un array dinamico ma
come
esempio penso possa andare bene
begin
TCatNum(CNList[0]).Count := 5;
TCatNum(CNList[0]).Descr := 'Shining';
TCatNum(CNList[0]).Color := clYellow;

TCatNum(CNList[1]).Count := 56;
TCatNum(CNList[1]).Descr := 'Middle';
TCatNum(CNList[1]).Color := $004080FF;

TCatNum(CNList[2]).Count := 65;
TCatNum(CNList[2]).Descr := 'Classic';
TCatNum(CNList[2]).Color := clRed;

TCatNum(CNList[3]).Count := 145;
TCatNum(CNList[3]).Descr := 'Strong';
TCatNum(CNList[3]).Color := clBlue;

TCatNum(CNList[4]).Count := 11;
TCatNum(CNList[4]).Descr := 'Professional';
TCatNum(CNList[4]).Color := clGreen;

Y := 5;
with PaintBox1.Canvas do
begin
Pen.Color := clBlack;
Pen.Style := psSolid;
for I := Low(CNList) to High(CNList) do
begin


{########################################################################}He
re Iwant to put the code the modify the Y variable but after most tentativei
didn't found nothing
{########################################################################}
Brush.Color := TCatNum(CNList[I]).Color;
Rectangle(X, Y, X * 4, Y * 4);
Brush.Color := Self..Color;
TextOut(X * 4 + 2, Y + 1, Format('%s: %d',
TCatNum(CNList[I]).Descr,
TCatNum(CNList[I]).Count]));
end;
end;
end;

Hi,sorry 4 my bad and little english:I want generate a legend but I'm unable
to do it, somebody can help me please??greetings:
Alfio



--
Willem van Deursen, The Netherlands
[email]wvandeursen_nospam (AT) nospam_carthago (DOT) nl[/email]
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.