如何在没有画布的控件上进行绘画呢?比如说Tpanel,他不具备画布的属性在上面写字画画都有困难。自己再把它包装一下吗?麻烦点吧!如何才能方便的进行处理呢?
看看这段代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
PRocedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
PanelCanvas: TCanvas;
begin
PanelCanvas := TControlCanvas.Create;
TControlCanvas(PanelCanvas).Control := Panel1;
PanelCanvas.Brush.Style := bsClear;
PanelCanvas.Pen.Color := clBlue;
PanelCanvas.Rectangle(2, 2, Panel1.Width - 2, Panel1.Height - 2);
PanelCanvas.Font.Name:='楷体_GB2312';
PanelCanvas.Font.Size:=24;
PanelCanvas.TextOut(Panel1.Width div 2,Panel1.Height div 2,'OK');
PanelCanvas.Free;
end;
end.
当少量应用时可以这样处理。当然如果要当量应用在没有画布的控件上绘画就用以上的方法把原来的控件包装一下开发一个新的控件,会更方便一些。
新闻热点
疑难解答
图片精选