📄 pscombo.pas
字号:
(* GREATIS PRINT SUITE *)
(* unit version 1.85.005 *)
(* Copyright (C) 2001-2007 Greatis Software *)
(* http://www.greatis.com/delphicb/printsuite/ *)
(* http://www.greatis.com/delphicb/printsuite/faq/ *)
(* http://www.greatis.com/bteam.html *)
unit PSCombo;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, PSPreview, PSCommon;
type
TPreviewComboBox = class(TCustomComboBox)
private
{ Private declarations }
FPreview: TCustomPreview;
FOnUpdate: TNotifyEvent;
procedure SetPreview(const Value: TCustomPreview);
function CleanText: string;
function CleanSelect: string;
function GetScales: string;
protected
{ Protected declarations }
procedure DropDown; override;
procedure Click; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure DoExit; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Update; override;
published
{ Published declarations }
property Preview: TCustomPreview read FPreview write SetPreview;
property Color;
property Ctl3D;
property Font;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property Visible;
property OnUpdate: TNotifyEvent read FOnUpdate write FOnUpdate;
end;
procedure Register;
implementation
{ TPreviewComboBox }
procedure TPreviewComboBox.SetPreview(const Value: TCustomPreview);
begin
if Value<>FPreview then
begin
if Assigned(FPreview) then FPreview.DeleteControlNotification(Self);
FPreview:=Value;
if Assigned(FPreview) then FPreview.AddControlNotification(Self);
Update;
end;
end;
function TPreviewComboBox.CleanText: string;
var
i: Integer;
begin
Result:=Text;
for i:=1 to Length(Result) do
if not (Result[i] in ['0'..'9']) then Delete(Result,i,1);
end;
function TPreviewComboBox.CleanSelect: string;
var
i: Integer;
begin
Result:=Items[ItemIndex];
for i:=1 to Length(Result) do
if not (Result[i] in ['0'..'9']) then Delete(Result,i,1);
end;
function TPreviewComboBox.GetScales: string;
const
EOL = #13#10;
var
i: Integer;
begin
Result:=strComboWholePage+EOL;
Result:=Result+strComboPageWidth+EOL;
for i:=Low(ScaleArray) to High(ScaleArray) do
Result:=Result+IntToStr(ScaleArray[i])+'%'+EOL;
end;
procedure TPreviewComboBox.DropDown;
begin
with Items do
begin
Text:=GetScales;
DropDownCount:=Count;
end;
inherited;
end;
procedure TPreviewComboBox.Click;
var
S: string;
begin
if Assigned(FPreview) then
begin
with Items,FPreview do
case ItemIndex of
0: ViewMode:=vmWholePage;
1: ViewMode:=vmPageWidth;
else
begin
S:=CleanSelect;
ViewMode:=vmCustom;
try
ViewScale:=StrToInt(S);
except
ShowMessage(strComboInvalidScale);
end;
end;
end;
end;
inherited;
end;
procedure TPreviewComboBox.KeyDown(var Key: Word; Shift: TShiftState);
var
S: string;
begin
if Assigned(FPreview) then
begin
case Key of
VK_RETURN:
begin
S:=CleanText;
with Items,FPreview do
begin
ViewMode:=vmCustom;
try
ViewScale:=StrToInt(S);
except
ShowMessage(strComboInvalidScale);
end;
end;
FPreview.SetFocus;
end;
VK_ESCAPE:
begin
FPreview.SetFocus;
Update;
end;
end;
end;
inherited;
end;
procedure TPreviewComboBox.KeyPress(var Key: Char);
begin
case Key of
Char(VK_BACK),Char(VK_DELETE),'0'..'9': inherited;
else Key:=#0;
end;
end;
procedure TPreviewComboBox.DoExit;
begin
inherited;
Update;
end;
procedure TPreviewComboBox.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
if (Operation=opRemove) and Assigned(FPreview) and (AComponent=FPreview) then
Preview:=nil;
end;
constructor TPreviewComboBox.Create(AOwner: TComponent);
begin
inherited;
Width:=125;
Height:=21;
Caption:=strNotLinked;
end;
destructor TPreviewComboBox.Destroy;
begin
if Assigned(FPreview) then FPreview.DeleteControlNotification(Self);
inherited;
end;
procedure TPreviewComboBox.Update;
begin
inherited;
if Assigned(FPreview) then Text:=FPreview.ScaleText
else Text:=strNotLinked;
if Assigned(FOnUpdate) then FOnUpdate(Self);
end;
procedure Register;
begin
RegisterComponents('Print Suite', [TPreviewComboBox]);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -