?
Solved

Draw line on Panel

Posted on 2001-08-21
12
Medium Priority
?
467 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

765 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