控件发布。
由于该软件所有控件均为个人编写。
由thx1180提交的报告说明其中一个控件出现BUG,现将该控件源码发布:
控件名称:TGondTrackBar
unit GondTrackBar;
interface
uses controls,Classes,Messages,Windows,ComCtrls,Commctrl,Consts,Graphics;
Type
TGondTrackBar=class(TGraphicControl)
private
FDrawing:Boolean;
FBaseDist:Real;
FMax:Integer;
FPosition:Integer;
FButtonPosX:Integer;
FButtonPosY:Integer;
FButtonOldX:Integer;
FButtonOldPosX:Integer;
FBitmap:TBitmap;
FButtonBitmap:TBitmap;
FTempBitmap:TBitmap;
FMouseDown:Boolean;
FOnChange: TNotifyEvent;
procedure SetBitmap(Value:TBitmap);
procedure SetButtonBitmap(Value:TBitmap);
procedure RefreshButtonPos(NewPosX,NewPosY:Integer);
procedure SetTempBitmapSize;
procedure SetMax(Value:Integer);
procedure SetJumpPosition(Value:Integer);
procedure SetPosition(X:Integer;Y:Integer);
procedure UpdateBaseDist;
procedure UpdateButtonPos;
protected
function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
override;
procedure Paint;
override;
procedure Resize;
override;
procedure MouseDown(Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
override;
procedure MouseMove(Shift: TShiftState;
X, Y: Integer);
Override;
procedure MouseUp(Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
override;
procedure Loaded;
override;
public
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
property Align;
property AutoSize;
property ShowHint;
property Max:Integer read FMax write SetMax;
property Position:Integer read FPosition write SetJumpPosition;
property Bitmap:TBitmap read FBitmap write SetBitmap;
property ButtonBitmap:TBitmap read FButtonBitmap write SetButtonBitmap;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Gond', [TGondTrackBar]);
end;
{ TGondTrackBar }
constructor TGondTrackBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width:=40;
Height:=20;
FMax:=10;
FDrawing:=False;
FButtonPosX:=0;
FButtonPosY:=0;
FBitmap:=TBitmap.Create ;
FButtonBitmap:=TBitmap.Create ;
FTempBitmap:=TBitmap.Create ;
end;
destructor TGondTrackBar.Destroy;
begin
FBitmap.Free;
FButtonBitmap.Free;
FTempBitmap.Free;
inherited Destroy;
end;
procedure TGondTrackBar.Paint;
begin
FDrawing:=True;
if csDesigning in ComponentState then
with inherited Canvasdo
begin
Pen.Style := psDash;
Brush.Style := bsClear;
Rectangle(0, 0, Width, Height);
end;
if FBitmap<>nil then
Canvas.Draw(0,0,FBitmap);
FDrawing:=False;
RefreshButtonPos(FButtonPosX,FButtonPosY);
end;
procedure TGondTrackBar.Resize;
begin
inherited;
UpdateBaseDist;
UpdateButtonPos;
end;
procedure TGondTrackBar.Loaded;
begin
inherited;
UpdateBaseDist;
UpdateButtonPos;
end;
procedure TGondTrackBar.SetBitmap(Value: TBitmap);
begin
FBitmap.Assign(Value);
Invalidate;
end;
procedure TGondTrackBar.SetButtonBitmap(Value: TBitmap);
begin
FButtonBitmap.Assign(Value);
UpdateButtonPos;
UpdateBaseDist;
Invalidate;
end;
procedure TGondTrackBar.SetTempBitmapSize;
begin
if not FButtonBitmap.Empty then
begin
if (FTempBitmap.Width<>FButtonBitmap.Width) or
(FTempBitmap.Height<>FButtonBitmap.Height) then
begin
FTempBitmap.Width:=FButtonBitmap.Width;
FTempBitmap.Height:=FButtonBitmap.Height;
end;
end;
end;
procedure TGondTrackBar.SetMax(Value: Integer);
begin
if Value<=0 then
Value:=10;
if FMax<>Value then
begin
FMax:=Value;
UpdateBaseDist;
end;
end;
procedure TGondTrackBar.UpdateBaseDist;
begin
if FButtonBitmap<>nil then
begin
FBaseDist:=(Width-FButtonBitmap.Width)/FMax;
SetJumpPosition(FPosition);
end;
end;
procedure TGondTrackBar.UpdateButtonPos;
begin
if FButtonBitmap<>nil then
FButtonPosY:=(Height-FButtonBitmap.Height) div 2;
end;
function TGondTrackBar.CanAutoSize(var NewWidth,
NewHeight: Integer): Boolean;
begin
Result:=True;
if not (csDesigning in ComponentState) or (FBitmap.Width>0)
and (FBitmap.Height>0) then
begin
if Align in [alNone,alLeft,alRight] then
NewWidth:=FBitmap.Width;
if Align in [alNone,alTop,alBottom] then
NewHeight:=FBitmap.Height;
end
end;
procedure TGondTrackBar.RefreshButtonPos(NewPosX, NewPosY: Integer);
var
FTempRect:TRect;
FTempButtonRect:TRect;
begin
if (not FButtonBitmap.Empty) and (not FDrawing) then
begin
if FTempBitmap.Empty then
SetTempBitmapSize
else
Canvas.Draw(FButtonPosX,FButtonPosY,FTempBitmap);
FButtonPosX:=NewPosX;
FTempRect:=Rect(0,0,FButtonBitmap.Width,FButtonBitmap.Height);
FTempButtonRect:=Rect(FButtonPosX,FButtonPosY,
FButtonPosX+FButtonBitmap.Width,FButtonPosY+FButtonBitmap.Height);
FTempBitmap.Canvas.CopyRect(FTempRect,Canvas,FTempButtonRect);
Canvas.Draw(FButtonPosX,FButtonPosY,FButtonBitmap);
end;
end;
procedure TGondTrackBar.SetJumpPosition(Value: Integer);
begin
if Value<0 then
Value:=0;
if Value>FMax then
Value:=FMax;
if (FPosition<>Value) and (not FMouseDown) then
begin
FPosition:=Value;
RefreshButtonPos(Round(FPosition*FBaseDist),FButtonPosY);
end;
end;
procedure TGondTrackBar.SetPosition(X, Y: Integer);
begin
if X<0 then
X:=0;
if X>Width-FButtonBitmap.Width then
X:=Width-FButtonBitmap.Width;
FPosition:=Round(X/FBaseDist);
RefreshButtonPos(X,FButtonPosY);
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TGondTrackBar.MouseDown(Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
FMouseDown:=True;
FButtonOldX:=X;
if (X<FButtonPosX) or (x>FButtonPosX+FButtonBitmap.Width) then
begin
FButtonOldPosX:=X-FButtonBitmap.Width div 2;
SetPosition(FButtonOldPosX,Y);
end else
FButtonOldPosX:=FButtonPosX;
inherited;
end;
procedure TGondTrackBar.MouseMove(Shift: TShiftState;
X, Y: Integer);
begin
if FMouseDown then
begin
SetPosition(FButtonOldPosX+(X-FButtonOldX),Y);
end;
inherited;
end;
procedure TGondTrackBar.MouseUp(Button: TMouseButton;
Shift: TShiftState;
X,
Y: Integer);
begin
FMouseDown:=False;
inherited;
end;
end.