Solved

Draw line on Panel

Posted on 2001-08-21
12
465 Views
Last Modified: 2010-04-06
Hi

How can i draw line on panel (TPanel does not have canvas like TForm) ?!


10x
Asi
0
Comment
Question by:asi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6409202
just drop a tshape on it or a picturebox and draw there a line
0
 
LVL 3

Accepted Solution

by:
Slavak earned 50 total points
ID: 6409217
or you can create a canvas :

Var
 ACanvas : TCanvas;
............................
  ACanvas := TControlCanvas.Create;
  TControlCanvas(ACanvas).Control := Panel;

 
0
 

Expert Comment

by:Aleq
ID: 6409234
TPanel has no DeviceContext, so only way to do this is to put TImage, TShape or similar component on the panel, set align to alClient (and optionally send it to the back).
----
procedure TForm1.Button1Click(Sender: TObject);
var
  Image: TImage;
begin
  Image:=TImage.Create(Panel1);
  Image.Align:=alClient;
  Image.Parent:=Panel1;
  Image.Transparent:=True;
  Image.Canvas.LineTo(Panel1.Width, Panel1.Height);
end;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:Aleq
ID: 6409237
ooops, I'm late...
ok, sorry.
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6409293
all window (TWinControl) have device context.

You can create canvas also as,

 ACanvas := TCanvas.Create;
 ACanvas.Handle := GetDC(Panel1.Handle);

but, i prefer a first way.

Note,
 GetDC(Panel1.Handle) give you a device context, that you can use with window API functions
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 6409343
The inheritance chain is the following:
TPanel <- TCustomPanel <- TCustomControl <- ...

TCustomControl has protected Canvas property, the problem is only that none of the descendants make it public.
A quick workaround:

type
  THackPanel = class(TPanel);

  with THackPanel(Panel1) do
  begin
    // you now have access to all protected properties
    Canvas.MoveTo(0, 0);
    Canvas.LineTo(ClientWidth, ClientHeight);
  end;

HTH
TOndrej
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6409385
thats it, tondrej :-)
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 6409395
yes kretzschmar :-)
I went through all the previous comments several times to make sure that none of them mentioned this well-known trick...
I was surprised :-P
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6409403
i know the trick, but thought not on it :-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6409415
btw tondrej (sorry to be off topic)
how are you?
what about mike lischke?
are you two working already together?

(many more questions in mind)
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 6409427
1. fine, busy, thanks :-)
2. fine too, busy, too :-)
3. yes! :-P
sorry for offtopic, I've included my e-mail in my profile, if you want to write
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6409453
i will email you, tondrej
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question