Panel on mapping by

 

     Recently produced FDS is a modeling tool, due to limited knowledge, the effect is to make 2D of. Yesterday, when the class teacher to draw a rectangular look, suddenly thought, why not give ordinary 2D plus a few straight lines drawn on the graphics, you can achieve 2D graphics 3D visual effect? So I do try to come back soon, sure enough, very good, very satisfied. But the test program code to FDS appears on the modeling tool when the problem: Panel did not Canvas property, can not say no, actually TPanel have to realize source in the Canvas property, but Protected not allow external access. How to do? Simple thought a moment, there are so several directions:

First, the Panel arranged to be transparent, in Form of Canvas drawing pattern on

Second, Panel inside plus a Canvas attribute components, and in that the top drawing

Third, think of ways Panel Implementation drawing on itself

By checking the data, change the source code and found a program, draw graphics always Panel shielded itself (this is because I need the program itself, Panel which also cover layer Panel ), a good solution is not found.

Option Two: In the Panel which added a Image component, but it raises more questions: As the assembly is dynamically generated, resulting in such as how to determine which component is added in the Image , in addition Image blocking the Panel 's incident response. In short it is not a good solution.

I walked a lot of detours before finally went to the third step. Finally, a Taiwan Delphi found the forum a similar question: How Panel designated to write the assembly http://delphi.ktop.com.tw/board.php?cid=168&fid=921&tid=70988 source code is C ++ , I previously learned a little C ++ , based on his understanding converted into Delphi , there may be wrong with it, but did not expect to actually run a success!

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

uses Math;

procedure TForm1.pnl1Click(Sender: TObject);

where

Panel:TPanel;

PanelCanvas:TControlCanvas;

begin

PanelCanvas:=TControlCanvas.Create;

PanelCanvas.Control:=pnl5;

Panel:=sender as TPanel;

with PanelCanvas do

begin

pen.Color:=clGreen;

MoveTo(Panel.Left,Panel.Top);

LineTo(Panel.left+round(Panel.Height/sqr(2)),Panel.top-round(Panel.Height/sqr(2)));

LineTo(Panel.left+Panel.Width+round(Panel.Height/sqr(2)),Panel.top-round(Panel.Height/sqr(2)));

LineTo(Panel.left+Panel.Width,Panel.top);

MoveTo(Panel.Left+Panel.Width,Panel.Top+Panel.Height);

LineTo(Panel.left+Panel.Width+round(Panel.Height/sqr(2)),Panel.top+Panel.Height-round(Panel.Height/sqr(2)));

LineTo(Panel.left+Panel.Width+round(Panel.Height/sqr(2)),Panel.top-round(Panel.Height/sqr(2)));

end;

PanelCanvas.Free;

end;

The key to success in TControlCanvas used, TControlCanvas of Control property enables Panel 's Canvas property can be accessed using.

看看TControlCanvasControl属性说明:Specifies the control associated with the control canvas object.

Guess you like

Origin www.cnblogs.com/blogpro/p/11426603.html