Delphi 的TPanel 是没有 Canavs属性的,因此无法直接在上面绘制图形。用下面的方法可以绕过限制,实现绘图的功能。
示例代码:
unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TForm2 = class(TForm) Panel1: TPanel; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); var PanelCanvas:TControlCanvas; begin PanelCanvas:=TControlCanvas.Create; PanelCanvas.Control:=panel1; with PanelCanvas do begin pen.Color:=clGreen; pen.Width:=5; MoveTo(0,0); LineTo(Panel1.Width,Panel1.Height); MoveTo(Panel1.Width-1,0); LineTo(0,Panel1.Height); end; PanelCanvas.Free; end; end.
按下Button后,会在 Panel 对角线绘制直线。
代码和可执行文件下载
你好,看到你写的这么多的Arduino的文章,其中关于USB方面的我们很感兴趣。在此想问一下,我们这里有一个开发USB Host Shield程序的项目,想请你帮帮忙,不知如何联系你?
我建议给我写邮件吧 wyanb@sina.com