发布一个显示点阵字的控件,UP得分 (100分)

  • 主题发起人 主题发起人 LeonSu
  • 开始时间 开始时间
L

LeonSu

Unregistered / Unconfirmed
GUEST, unregistred user!
Active是用来让字滚动的,暂时没写代码。
欢迎交流。
unit LeonSuMatrix;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, Graphics, Dialogs, ExtCtrls, Math;

type
TLeonSuMatrix = class(TGraphicControl)
private
FActive: Boolean;
FText: String;
FImage: TBitmap;
FOffset_H: Integer;
FOffset_V: Integer;
procedure SetActive(Value: Boolean);
procedure SetText(Value: String);
procedure SetOffset_H(Value: Integer);
procedure SetOffset_V(Value: Integer);
{ Private declarations }
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
{ Public declarations }
published
property Active: Boolean read FActive write SetActive default False;
property Color;
property Font;
property Offset_H: Integer read FOffset_H write SetOffset_H;
property Offset_V: Integer read FOffset_V write SetOffset_V;
property Text: String read FText write SetText;
{ Published declarations }
end;

const
BackColor=$007F7F7F;

implementation

constructor TLeonSuMatrix.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FActive:=False;
Color:=clBlack;
FImage:=TBitmap.Create;
Font.Color:=clYellow;
Font.Size:=12;
Font.Name:='宋体';
Offset_V:=1;
Offset_H:=1;
end;

destructor TLeonSuMatrix.Destroy;
begin
FImage.Destroy;
inherited Destroy;
end;

procedure TLeonSuMatrix.Paint;
Const
FScale=3;//放大倍数,最好为3,如果变大的话,会比较难看
var
i,j:Integer;
VOffSet,HOffset: Integer;
//VOffset:增加的高度,HOffset
trgRect,srcRect: TRect;
Bmp: TBitmap;
begin
Canvas.Lock;
Bmp:=TBitmap.Create;
FImage.Canvas.Font:=Font;
FImage.Canvas.Brush.Color:=Color;

VOffset:=FOffset_V*FScale;
HOffset:=FOffset_H*FScale;
Height:=Abs(Font.Height)*FScale+VOffset*2;

FImage.Width:=FImage.Canvas.TextWidth(FText);
FImage.Height:=FImage.Canvas.TextHeight(FText);
FImage.Canvas.TextOut(0,0,FText);

Bmp.Height:=Height;
Bmp.Width:=Width;
Bmp.Canvas.Brush.Color:=Color;
Bmp.Canvas.FillRect(Rect(0,0,Bmp.Width,Bmp.Height));

trgRect:=Rect(HOffset,VOffset-2,FImage.Width * FScale+HOffset,FImage.Height * FScale+Voffset-2);
srcRect:=Rect(0,0,FImage.Width,FImage.Height);

Bmp.Canvas.CopyRect(trgRect,FImage.Canvas,srcRect);
for i:=0 to Bmp.Width do
for j:=0 to Bmp.Height do
begin
If ((i mod FScale=1)and(j mod FScale=1))or((i mod FScale=2)and(j mod FScale=2)) then
begin
If Bmp.Canvas.Pixels[i,j]=Color then
Bmp.Canvas.Pixels[i,j]:=BackColor;
end
else
If (i mod FScale=0)or(j mod FScale=0) then
Bmp.Canvas.Pixels[i,j]:=Color;
end;
Canvas.Draw(0,0,BMP);
Bmp.Free;
Canvas.Unlock;
// inherited Paint;
end;

procedure TLeonSuMatrix.SetActive(Value: Boolean);
begin
If Value<>FActive then
begin
FActive:=Value;
end;
end;

procedure TLeonSuMatrix.SetText(Value: String);
begin
If Trim(Value)<>FText then
begin
FText:=Trim(Value);
Repaint;
// Invalidate;
end;
end;

procedure TLeonSuMatrix.SetOffset_V(Value: Integer);
begin
If Value<>FOffset_V then
begin
FOffset_V:=Value;
Repaint;
// Invalidate;
end;
end;

procedure TLeonSuMatrix.SetOffset_H(Value: Integer);
begin
If Value<>FOffset_H then
begin
FOffset_H:=Value;
Repaint;
// Invalidate;
end;
end;

end.
 
惨了!!!!!!!!!!
为什么会这样,我提交时,系统说出错,害得我重提交一次,结果现在又显示出来。
多扣了100分,天哪!!!!!!
版主,这是怎么回事?我可不可以回收这个分数!
 
试用。
怎样用?
procedure TForm1.Button1Click(Sender: TObject);
var
i: TLeonSuMatrix;
begin
i:=TLeonSuMatrix.Create(form1);
i.Left:=20;
i.Top:=30;
i.Parent:=form1;
i.Text:='测试';
i.Color:=clred;
i.Font.Size:=24;
i.Active:=True;
end;
没反应。
 
加上:
i.height:=100;
i.width:=400;
 
因为我是直接把控件拖到一个窗口中,而DELPHI自动给加上了HEIGHT和WIDTH,所以没注意
到这点,以后会注意的。
可以修改源码:
在Create事件中的Inherited Create(AOwner);一句的后面加上:
Height:=100;
Width:=100;
OK
 
大家说,如果改为从LABEL继承下来会好一些吗?
速度可以更快一点吗?
我试了一下,感觉差不多。
 
完成了,
把ACTIVE的代码加上了,
另外还增加两个属性:Offset_Hor与Offset_Ver,用来改变横轴与纵轴的偏移,
要的话,去ftp://ispig.3322.org/控件/LeonSuMatrix.pas下吧!
 
怎么速度那么慢?有没有什么地方可以调快一点?[:(]
 
Interval是改变Timer的响应时间,
Step是每次移动多少格。
 

Similar threads

后退
顶部