用DELPHI模拟LED屏下的那种文字特效怎么做啊?
如:左移入
右移入
上移入
下移入
左展入
右展入
上展入
下展入
横向展开
横向闭合
纵向展开
纵向闭合
水平百叶窗
垂直百叶窗
闪烁
同时显示

解决方案 »

  1.   

    在正常的屏幕上模拟并不是一件很容易的事,如果你还追求“点阵”效果的话。
    这需要读取字库,并取出点阵来。
    否则倒是不算难,正常地画文本就行了,如果嫌麻烦,还可以写到TLabel上,再移动TLabel就行了
      

  2.   

    我自己做了一个控件,这是完整的源代码,没有控件注册部份的代码,自己加上去吧。unit LeonSuMatrix;interfaceuses
      Windows, Messages, SysUtils, Classes, Controls, Graphics, Dialogs,
      ExtCtrls, Math;type
      TMoveDirection=(mdLeft,mdRight,mdUp,mdDown);  TLeonSuMatrix = class(TGraphicControl)
      private
        FMatrix_Left: Integer;
        FMatrix_Top: Integer;
        FActive: Boolean;
        FText: String;
        FImage: TBitmap;
        FInterVal: Word;
        FMoveDirection: TMoveDirection;
        FOffset_Hor: Word;
        FOffset_Ver: Word;
        FOnMouseEnter: TNotifyEvent;
        FOnMouseLeave: TNotifyEvent;
        FOnStart: TNotifyEvent;
        FOnStop: TNotifyEvent;
        FStep: Byte;
        FTimer: TTimer;
        procedure SetActive(Value: Boolean);
        procedure SetInterVal(Value: Word);
        procedure SetMoveDirection(Value: TMoveDirection);
        procedure SetStep(Value: Byte);
        procedure SetText(Value: String);
        procedure SetOffset_Hor(Value: Word);
        procedure SetOffset_Ver(Value: Word);
        procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
        procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
        procedure MyOnTimer(Sender: TObject);
        procedure DrawMatrix(Matrix_X,Matrix_Y: Integer);
        { Private declarations }
      protected
        procedure Start; dynamic;
        procedure Stop; dynamic;
        { 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 Interval: Word read FInterval write SetInterval default 100;
        property MoveDirection: TMoveDirection read FMoveDirection
                                write SetMoveDirection default mdLeft;
        property Offset_Hor: Word read FOffset_Hor write SetOffset_Hor;
        property Offset_Ver: Word read FOffset_Ver write SetOffset_Ver;
        property ParentFont;
        property ParentColor;
        property ParentShowHint;
        property ShowHint;
        property Step: Byte read FStep write SetStep default 3;
        property Hint;
        property Text: String read FText write SetText;
        property OnClick;
        property OnMouseDown;
        property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
        property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
        property OnMouseMove;
        property OnMouseUp;
        property OnStart: TNotifyEvent read FOnStart write FOnStart;
        property OnStop: TNotifyEvent read FOnStop write FOnStop;
        { Published declarations }
      end;const
      BackColor=$007F7F7F;implementationconstructor TLeonSuMatrix.Create(AOwner: TComponent);
    begin
     inherited Create(AOwner);
     FImage:=TBitmap.Create;
     FTimer:=TTimer.Create(Self);
     FTimer.Enabled:=False;
     FTimer.OnTimer:=MyOnTimer;
     FActive:=False;
     Color:=clBlack;
     Font.Color:=clYellow;
     Font.Size:=12;
     Font.Name:='宋体';
     FOffset_Ver:=0;
     FOffset_Hor:=0;
     Height:=100;
     Width:=100;
     FMoveDirection:=mdLeft;
     FInterval:=10;
     FStep:=1;
     FMatrix_Left:=FOffset_Hor;
     FMatrix_Top:=FOffset_Ver;
    end;destructor TLeonSuMatrix.Destroy;
    begin
     FImage.Free;;
     FTimer.Free;
     inherited Destroy;
    end;procedure TLeonSuMatrix.CMMouseEnter(var Message: TMessage);
    begin
      if Assigned(FOnMouseEnter) then FOnMouseEnter(self);
      inherited;
    end;procedure TLeonSuMatrix.CMMouseLeave(var Message: TMessage);
    begin
      if Assigned(FOnMouseLeave) then FOnMouseLeave(self);
      inherited;
    end;procedure TLeonSuMatrix.MyOnTimer(Sender: TObject);
    begin
     DrawMatrix(FMatrix_Left,FMatrix_Top);
     Case FMoveDirection of
       mdLeft:begin
               If FMatrix_Left<=-FImage.Width then
                FMatrix_Left:=(Width+FImage.Width) div 3
               else
                Dec(FMatrix_Left,FStep);
    //           Canvas.TextOut(0,0,inttoStr(FMatrix_Left*3));
              end;
      mdRight:begin
               If FMatrix_Left*3>=Width then
                FMatrix_Left:=-FImage.Width
               else
                Inc(FMatrix_Left,FStep);
    //           Canvas.TextOut(0,0,inttoStr(FMatrix_Left));
              end;
         mdUp:begin
               If FMatrix_Top<=-FImage.Height then
                FMatrix_Top:=(Height+FImage.Height) div 3
               else
                Dec(FMatrix_Top,FStep);
    //           Canvas.TextOut(0,0,inttoStr(FMatrix_Top*3));
              end;
       mdDown:begin
               If FMatrix_Top*3>=Height then
                FMatrix_Top:=-FImage.Height
               else
                Inc(FMatrix_Top,FStep);
    //           Canvas.TextOut(0,0,inttoStr(FMatrix_Top));
              end;
     end;
    // Repaint;
    end;procedure TLeonSuMatrix.DrawMatrix(Matrix_X,Matrix_Y: Integer);
    Const
     FScale=3;//放大倍数,只能为3
    var
     i,j:Integer;
    // TopOffset: Integer;
    // LeftOffset: Integer;
     //TopOffset:增加的高度,LeftOffset
     trgRect,srcRect: TRect;
     Bmp: TBitmap;
    begin
     Canvas.Lock;
     Bmp:=TBitmap.Create;
     FImage.Canvas.Font:=Font;
     FImage.Canvas.Brush.Color:=Color;// TopOffset:=(FOffset_Ver)*FScale;//纵轴,从上至下,Height
    // LeftOffset:=(FOffset_Hor)*FScale;//横轴,从左至右,Width Height:=Abs(Font.Height)*FScale+2*FOffset_Ver*FScale; FImage.Width:=FImage.Canvas.TextWidth(FText)+2*FOffset_Hor;
     FImage.Height:=FImage.Canvas.TextHeight(FText)+2*FOffset_Ver; FImage.Canvas.FillRect(Rect(0,0,FImage.Width,FImage.Height));
     FImage.Canvas.TextOut(FOffset_Hor,FOffset_Ver,FText); Bmp.Height:=Height;
     Bmp.Width:=Width;
     Bmp.Canvas.Brush.Color:=Color; Bmp.Canvas.FillRect(Rect(0,0,Bmp.Width,Bmp.Height)); trgRect:=Rect(Matrix_X*FScale,//+LeftOffset,
                   Matrix_Y*FScale,
                   Matrix_X*FScale+FImage.Width * FScale,//+LeftOffset,
                   Matrix_Y*FScale+FImage.Height * FScale);
     srcRect:=Rect(0,0,FImage.Width,FImage.Height); Bmp.Canvas.CopyRect(trgRect,FImage.Canvas,srcRect);
     for i:=0 to Bmp.Width-1 do
      for j:=0 to Bmp.Height-1 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;
    end;procedure TLeonSuMatrix.Paint;
    begin
     DrawMatrix(0,0);
    // inherited Paint;
    end;procedure TLeonSuMatrix.SetActive(Value: Boolean);
    begin
     If Value<>FActive then
     begin
      FActive:=Value;
      If Value and (FMoveDirection=mdLeft) then
       FMatrix_Left:=(FImage.Height+Width)div 3
      else
       FMatrix_Left:=0;
      FMatrix_Top:=0;
      DrawMatrix(FMatrix_Left,FMatrix_Top);
      FTimer.Enabled:=Value;
     end;
    end;procedure TLeonSuMatrix.SetInterVal(Value: Word);
    begin
     If Value<>FInterVal then
     begin
      FInterVal:=Value;
      FTimer.Interval:=Value;
     end;
    end;procedure TLeonSuMatrix.SetMoveDirection(Value: TMoveDirection);
    begin
     If Value<>FMoveDirection then
     begin
      FMoveDirection:=Value;
      If FActive then
      begin
       FActive:=False;
       FTimer.Enabled:=FActive;
       DrawMatrix(0,0);
      end;
     end;
    end;procedure TLeonSuMatrix.SetStep(Value: Byte);
    begin
     If Value<>FStep then
      FStep:=Value;
    end;procedure TLeonSuMatrix.SetText(Value: String);
    begin
     If Trim(Value)<>FText then
     begin
      FText:=Trim(Value);
      DrawMatrix(FMatrix_Left,FMatrix_Top);
    //  Invalidate;
     end;
    end;procedure TLeonSuMatrix.SetOffset_Ver(Value: Word);
    begin
     If Value<>FOffset_Ver then
     begin
      FOffset_Ver:=Value;
      DrawMatrix(0,0);
    //  Invalidate;
     end;
    end;procedure TLeonSuMatrix.SetOffset_Hor(Value: Word);
    begin
     If Value<>FOffset_Hor then
     begin
      FOffset_Hor:=Value;
      DrawMatrix(0,0);
    //  Invalidate;
     end;
    end;procedure TLeonSuMatrix.Start;
    begin
      if Assigned(FOnStart) then FOnStart(Self);
    end;procedure TLeonSuMatrix.Stop;
    begin
      if Assigned(FOnStop) then FOnStop(Self);
    end;end.