Q&A

  • 컴포넌트 만들기에서 좌초(?)중 헬프여 ^^;
아래 소스는 책보고 한건데여...여기서 TransParents를 더 추가해서

(움직이는 메모 텍스트에여...)

바탕화면두 투명하게 할려구 하는데 잘 안되네여..

고수님들의 조언 부탁드리구여....



고칠부분은 맨 밑부분쯤에 있어여...(기타 다른 부분도 손바주시면 고맙구여..)





//////////////////////////

unit moveText;



interface



uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

ExtCtrls, FlatUtilitys,

// WinProcs, WinTypes,

StdCtrls,

WPRTFInp,

WPReader, WPDefs, Clipbrd, WPObj, WPRead2, WPWrite2,

WPwrtRTF, WPrtfTXT, WPRtfIo, WPFinder,

WPRtfPA, WPWinCTR, WPPrint;





type

TAlignment = (taCenter, taLeftJustify, taRightJustify);

TTextStyle = (tsNormal, tsRaised, tsLowered, tsShaddow);

TMoveDirection = (mdStatic, mdRightToLeft, mdLeftToRight, mdTopToBottom, mdBottomToTop);

TCustomMoveText = class(TGraphicControl)



private

FAlignment: TAlignment;

FTextStyle: TTextStyle;

FMoveDirection: TMoveDirection;

FTimer: TTimer;

FItems: TStringList;

FColor: TColor;

FContinuous: Boolean;

FFont: TFont;

FOnBegin, FOnStep, FOnEnd: TNotifyEvent;

FSteps, FSpeed, FDepth, LineHi, FCurrentStep, FTextWidth, FTextHeight, XPos, YPos: integer;

FTransparent: Boolean; //

procedure SetTransparent (const Value: Boolean); //

procedure SetAlignment(Value: TAlignment);

procedure SetContinuous(Value: Boolean);

procedure SetItems(Value: TStringList);

procedure DataChanged;

procedure SetTextStyle(Value: TTextStyle);

procedure SetDirection(Value: TMoveDirection);

procedure SetSteps(Value: Integer);

procedure SetSpeed(Value: Integer);

procedure SetColor(Value: TColor);

procedure SetFont(Value: TFont);

procedure SetDepth(Value: Integer);

procedure SetSizeParams;

procedure FontChanged(Sender: Tobject);

procedure DoTextOut(ACanvas: TCanvas; X, Y: Integer; AText: string);



{ Private declarations }

protected

procedure Paint; override;

procedure TimerTick(Sender: TObject);

property Alignment: TAlignment read FAlignment write SetAlignment;

property Depth: Integer read FDepth write SetDepth default 1;

property MoveDirection: TMoveDirection read FMoveDirection write SetDirection default mdRightToLeft;

property Items: TStringList read FItems write SetItems;

property OnBegin: TNotifyEvent read FOnBegin write FOnBegin;

property OnStep: TNotifyEvent read FOnStep write FOnStep;

property OnEnd: TNotifyEvent read FOnEnd write FOnEnd;



// procedure Paint; override; //



{ Protected declarations }

public

Property CurrentStep: Integer read FCurrentStep;

constructor Create(AOwner: TComponent); override;

destructor Destroy; override;

procedure ReverseDirection;

procedure MoveStart(StartingStep: Integer);

procedure MoveStop;



{ Public declarations }

published

property TextStyle: TTextStyle read FTextStyle write SetTextStyle default tsNormal;

property Steps: Integer read FSteps write SetSteps default 66;

property Speed: Integer read FSpeed write SetSpeed default 200;

property Color: TColor read FColor write SetColor default clBtnFace;

property Continuous: Boolean read FContinuous write SetContinuous;

property Font: TFont read FFont Write SetFont;

property Transparent: Boolean read FTransparent write SetTransparent default false;

{ Published declarations }

end;



TMoveText = class(TCustomMoveText)

published

property Align;

property Alignment;

property Font;

property MoveDirection;

property ShowHint;

property Speed;

property Steps;

property Visible;

property OnBegin;

property OnStep;

property Color;

property Depth;

property Items;

property TextStyle;

property ParentShowHint;

// property TransParent;

end;



///////////////////////////////////////



procedure Register;



implementation



procedure Register;

begin

RegisterComponents('Samples', [TmoveText]);

end;



constructor TCustomMoveText.Create(AOwner: TComponent);

begin

inherited Create(AOwner);

ControlStyle :=ControlStyle - [csOpaque];

FItems := TStringList.Create;

FItems.Add('텍스트를 움직입니다.');



Width:=200;

Height:=20;

FColor:=clBtnFace;

FSteps:=80;

FCurrentStep:=0;

FDepth:=1;

FContinuous:=true;

FTextStyle:=tsNormal;

Falignment:=taCenter;

FFont:=TFont.Create;

with FFont do

begin

name:='굴림체';

Size:=10;

Color:=clBlack;

end;

FFont.OnChange :=FontChanged;

FTimer:=TTimer.Create(Self);

FSpeed:=100;

With FTimer do

begin

Enabled:=false;

OnTimer:=TimerTick;

Interval:=FSpeed;

end;



FMoveDirection := mdRightToLeft;

SetDirection(FMoveDirection);

end;



destructor TCustomMoveText.Destroy;

begin

FItems.Free;

FTimer.free;

FFont.Free;

inherited Destroy;

end;



procedure TCustomMoveText.SetItems(Value: TStringList);

begin

if FItems <> Value then

begin

FItems.Assign(Value);

DataChanged;

end;

end;



procedure TCustomMoveText.DoTextOut(ACanvas: TCanvas; X, Y: Integer; AText: string);

var

TextAdjustment:integer;

begin

with ACanvas do

begin

Font:= FFont;

Brush.Style := bsClear;

if FAlignment = taCenter then

TextAdjustment := Round((FTextWidth/2)-(TextWidth(AText)/2))

else if Falignment = taRightJustify then

TextAdjustment := Round(FTextWidth - TextWidth(AText))

else TextAdjustment:=0;



case FTextStyle of

tsRaised: begin

Font.Color :=clBtnHighlight;



TextOut(X-FDepth+TextAdjustment, Y-FDepth, AText);

Font.Color :=clBtnShadow;



TextOut(X+FDepth+TextAdjustment, Y+FDepth, AText);

end;

tsLowered: begin

Font.Color :=clBtnShadow;



TextOut(X-FDepth+TextAdjustment, Y-FDepth, AText);

Font.Color :=clBtnHighlight;



TextOut(X+FDepth+TextAdjustment, Y+FDepth, AText);

end;

tsShaddow: begin

Font.Color :=clBtnShadow;



TextOut(X+FDepth+TextAdjustment, Y+FDepth, AText);

end;

end;

Font.Color :=FFont.Color;

TextOut(X+TextAdjustment, Y, AText);

end;

end;



procedure TCustomMoveText.Paint;

var

TmpBmp: TBitMap;

StartXPos, StartYPos, I:integer;

PercentDone: Double;

begin

SetSizeParams;

TmpBmp:=TBitMap.Create;

try

TmpBmp.Width :=Width;

TmpBmp.Height :=Height;

with TmpBmp.Canvas do

begin

Font := FFont;

Brush.Color := FColor;

Brush.Style := bsSolid;

FillRect(ClipRect);

end;



if FTextWidth >= Width then

XPos:=0

else

XPos:=(Width-FTextWidth) div 2;

if FTextHeight >=Height then

YPos:=0

else

YPos:=(Height-FTextHeight) div 2;



if csDesigning in ComponentState then

PercentDone :=0.5

else

PercentDone:=FCurrentStep/FSteps;



case FMoveDirection of

mdRightToLeft: begin

StartYPos:=YPos;

StartXPos:=Round((FTextWidth + Width)*(1-PercentDone))-FTextWidth;

end;

mdLeftToRight: begin

StartYPos:=YPos;

StartXPos:=Round((FTextWidth + Width)*PercentDone)-FTextWidth;

end;

mdBottomToTop: begin

StartXPos:=YPos;

StartYPos:=Round((FTextHeight + Height)*(1-PercentDone))-FTextHeight;

end;

mdTopToBottom: begin

StartXPos:=YPos;

StartYPos:=Round((FTextHeight + Height)*PercentDone)-FTextHeight;

end;

else

begin

StartXPos:=XPos;

StartYPos:=YPos;

end

end;

I:=0;

while I < FItems.Count do

begin

DoTextOut(TmpBmp.canvas, StartXPos, StartYPos, FItems.Strings[I]);

Inc(StartYPos, LineHi);

Inc(I);

end;

canvas.Draw(0,0,TmpBmp);

Finally

TmpBmp.free;

end;



end;





procedure TCustomMoveText.SetSizeParams;

var

S: String;

I, SWidth: Integer;

Metrics: TTextMetric;

begin

with Canvas do

begin

Font:=FFont;

GetTextMetrics(Handle,Metrics);

LineHi:=Metrics.tmHeight + Metrics.tmInternalLeading;

if FTextStyle in [tsRaised, tsLowered] then

LineHi:=LineHi+2*FDepth

else if FTextStyle in [tsShaddow] then

LineHi := LineHi + FDepth;

end;

FTextWidth :=0;

I:=0;

while I < FItems.Count do

begin

S:=FItems.Strings[I];

SWidth:=Canvas.TextWidth(S);

if FTextStyle in [tsRaised, tsLowered] then

SWidth :=SWidth + 2 *FDepth

else if FTextStyle in [tsShaddow] then

SWidth :=SWidth+FDepth;

if FTextWidth < SWidth then

FTextWidth:=SWidth;

Inc(I);

end;

FTextHeight:=LineHi*FItems.Count;

if FTextHeight >= Width then

XPos:=0

else

XPos := (Width-FTextWidth) div 2;

if FTextHeight >=Height then

YPos:=0

else

YPos := (Height - FTextHeight) div 2;

end;



procedure TCustomMoveText.SetContinuous(Value: Boolean);

begin

if FContinuous <> Value then

begin

FContinuous := Value;

if FMoveDirection <> mdStatic then

MoveStart(FCurrentStep);

end;

end;



procedure TCustomMoveText.SetSteps(Value: Integer);

begin

if FSteps <> Value then

begin

FSteps:=Value;

if csDesigning in ComponentState then

Invalidate;

end;

end;



procedure TCustomMoveText.SetSpeed(Value: Integer);

begin

if FSpeed <> Value then

begin

if Value > 1000 then Value :=1000

else if Value < 1 then Value :=1;

FSpeed:=Value;

if FTimer <> nil then FTimer.Interval := FSpeed;

end;

end;



procedure TCustomMoveText.SetColor(Value: TColor);

begin

if FColor <> Value then

begin

FColor :=Value;

DataChanged;

end;

end;



procedure TCustomMoveText.FontChanged(Sender: TObject);

begin

DataChanged;

end;



procedure TCustomMoveText.SetFont(Value: TFont);

begin

if FFont <> Value then

begin

FFont.Assign(Value);

DataChanged;

end;

end;



procedure TCustomMoveText.MoveStop;

begin

FTimer.Enabled :=false;

end;



procedure TCustomMoveText.ReverseDirection;

begin

if FMoveDirection=mdStatic then Exit;

FCurrentStep := FSteps - FCurrentStep;

case FMoveDirection of

mdLeftToRight: FMoveDirection := mdRightToLeft;

mdRightToLeft: FMoveDirection := mdLeftToRight;

mdTopToBottom: FMoveDirection := mdBottomToTop;

mdBottomToTop: FMoveDirection := mdTopToBottom;

end;

end;



procedure TCustomMoveText.TimerTick(Sender: TObject);

begin

if not FTimer.Enabled then Exit;

if (FCurrentStep=0) and Assigned(FOnBegin) then

FOnBegin(Self);

Inc(FCurrentStep);

Paint;

if Assigned(FOnStep) then

FOnStep(Self);

if FCurrentStep > FSteps then

begin

FTimer.Enabled :=false;

if Assigned(FOnEnd) then

FOnEnd(Self);

FCurrentStep :=0;

if FContinuous then

MoveStart(FCurrentStep);

end;

end;



procedure TCustomMoveText.DataChanged;

begin

SetSizeParams;

Invalidate;

end;



procedure TCustomMoveText.SetTextStyle(Value: TTextStyle);

begin

if FTextStyle <> Value then

begin

FTextStyle := Value;

DataChanged;

end;

end;



procedure TCustomMoveText.SetDirection(Value: TMoveDirection);

begin

if FMoveDirection <> Value then

FMoveDirection := Value;

if FMoveDirection = mdStatic then

MoveStop

else

MoveStart(FCurrentStep);

end;



procedure TCustomMoveText.SetAlignment(Value: Talignment);

begin

if FAlignment <> Value then

begin

Falignment:=Value;

DataChanged;

end;

end;



procedure TCustomMoveText.SetDepth(Value: Integer);

begin

if FDepth <> Value then

begin

FDepth := Value;

DataChanged;

end;

end;



procedure TCustomMoveText.MoveStart(StartingStep: Integer);

begin

if FTimer.Enabled then Exit;

if (StartingStep >= 0) and (StartingStep <= FSteps) then

FCurrentStep := StartingStep;

FTimer.Enabled :=true;

end;



procedure TCustomMoveText.SetTransparent(const Value: Boolean);

begin

//***** 이 부분을 채워 주세요..

end;



end.



0  COMMENTS
    • 송길수
    • 2001.01.27 05:11
    • 4 COMMENTS
    • /
    • 0 LIKES
    • 김광섭
      2001.01.27 22:38
      송길수 wrote: > 특정한 프로그램 소스를 불러서 수정을 하려 했더니.... > > Objct Inspector(F11누르...
    • 최용일
      2001.01.27 05:17
      안녕하세요. 최용일입니다. 안보이시면 F11누르면 나옵니다. 아님 메뉴에서 불러오셔두 되구요... 프...
    • 송길수
      2001.01.27 18:56
      최용일 wrote: 최용일님의 글은 잘 읽었지만... F11키를 눌러 보아도 안나오고.... 다시 실행을 시...
    • 최용일
      2001.01.30 09:47
      안녕하세요. 최용일입니다. 델파이 Bin폴더에 보시면 delphi32.dsk란 파일이 있습니다. 이걸 편집하시면...
    • 최용일
      2001.01.27 05:12
      안녕하세요. 최용일입니다. 에디트의 OnKeyDown이벤트나 OnKeyPress이벤트같은곳에다 코딩하면 알수 있...
    • 뻐록이
      2001.01.27 05:07
      바보감자 wrote: > 안녕하세여... > 말그대로입니다... > 예를 들어...에디트1에서 엔터 치면말이죠... ...
    • onlydel
      2001.01.29 05:19
      내폼위에 Word를 가져오고 싶다면 OleContainer를 사용하시는게 좋겠군요. 우선 폼위에 OleContainer를 올...
    • lsb
    • 2001.01.27 03:38
    • 0 COMMENTS
    • /
    • 0 LIKES
    • 방경주
      2001.01.27 10:01
      두 디비가 같이 들어 있다면 같은 알리아스 상에 존재하는 것인가여? 구럼 간단하지 않은가? Select ...
    • 바보감자
      2001.01.27 18:37
      방경주 wrote: > 두 디비가 같이 들어 있다면 같은 알리아스 상에 존재하는 것인가여? > > 구럼 간단하...
    • cico
    • 2001.01.27 03:01
    • 3 COMMENTS
    • /
    • 0 LIKES
    • 바보감자
      2001.01.27 03:33
      cico wrote: > procedure 와 function의 정확한 차이점이 궁금하군여... > > 글구 const는 어떨때 사용...
    • cico
      2001.01.27 11:29
      바보감자 wrote: > cico wrote: > > procedure 와 function의 정확한 차이점이 궁금하군여... > > > >...
    • 바보감자
      2001.01.27 19:43
      cico wrote: > 바보감자 wrote: > > cico wrote: > > > procedure 와 function의 정확한 차이점이 궁금...
    • 최용일
      2001.01.27 05:01
      안녕하세요. 최용일입니다. 에러 내용을 보면 크기 제한하고는 상관이 없는거 같군요... PACK_START_...
    • Mpeg2 maker
      2001.01.27 17:27
      같은 유닛에 지정된 상수인데요... 제가 그 부분만 가지고 3일째 헤매고 있습니다. const문에 정의된 P...
    • 나원참
    • 2001.01.27 02:51
    • 3 COMMENTS
    • /
    • 0 LIKES
    • 바보감자
      2001.01.27 03:51
      나원참 wrote: > 전 왕 델초 입니다. > 프로시저를 선언한뒤 > 값을 받아야 되는데 > 이 프로시저가 제...
    • 나원참
      2001.01.27 05:53
      바보감자 wrote: > 나원참 wrote: > > 전 왕 델초 입니다. > > 프로시저를 선언한뒤 > > 값을 받아야 ...
    • 나그네
      2001.01.27 06:24
      글쿤요... With Proc do begin Prepare; ParambyName('TEC').AsString = '인자값넣기'; ExecProc...
    • 왕초보
    • 2001.01.27 02:08
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 권영길
      2001.01.27 02:40
      project->option->packages->indy제거.. tools->environment->library->directory제거 왕초보 wrote: ...
    • 김범수
    • 2001.01.27 02:06
    • 1 COMMENTS
    • /
    • 0 LIKES
    • 바보감자
      2001.01.27 03:52
      김범수 wrote: > dbgrid을 세로로 출력하는 방법은 없나요. > 조언 부탁합니다. 저두 해결 방법은 ...
    • 이승근
    • 2001.01.27 00:18
    • 2 COMMENTS
    • /
    • 0 LIKES
    • 바보감자
      2001.01.27 03:58
      이승근 wrote: > 그리고, 혹시 dbgrid에서 특정 field에 입력하면 그 값을 체크하여 어떤 결과값을 줄수있...
    • 이승근
      2001.01.27 19:02
      바보감자 wrote: > 이승근 wrote: > > 그리고, 혹시 dbgrid에서 특정 field에 입력하면 그 값을 체크하여...
    • 뿌요
      2001.01.31 19:12
      edit3의 exit event나 keypress event에서 쿼리실행시킨다.. with query do begin Close; S...
    • 바보감자
      2001.01.27 04:00
      권세용 wrote: > 안녕하세요... 제가 워낙 무능력해서.. 이렇게 도움을 부탁드립니다. > > edit box에 ...