asimpred.pas
来自「delphi编程控件」· PAS 代码 · 共 309 行
PAS
309 行
unit asimpred;
(*
COPYRIGHT (c) RSD Software 1997 - 98
All Rights Reserved.
*)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, AImCtrls;
type
TFAutoSpinImagePropEditor = class(TForm)
Panel1: TPanel;
bAdd: TButton;
bInsert: TButton;
bDelete: TButton;
Panel2: TPanel;
Panel3: TPanel;
Edit1: TEdit;
ListBox: TAutoImageListBox;
bUp: TButton;
bDown: TButton;
LabelHint: TLabel;
bClear: TButton;
LabelValue: TLabel;
LabelImageIndex: TLabel;
Edit2: TEdit;
BOk: TButton;
bCancel: TButton;
bHelp: TButton;
SpinImage: TAutoSpinImage;
Edit3: TMemo;
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit2Exit(Sender: TObject);
procedure bAddClick(Sender: TObject);
procedure bInsertClick(Sender: TObject);
procedure bDeleteClick(Sender: TObject);
procedure Edit1Exit(Sender: TObject);
procedure ListBoxClick(Sender: TObject);
procedure bUpClick(Sender: TObject);
procedure bDownClick(Sender: TObject);
procedure ListBoxDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure ListBoxDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure bClearClick(Sender: TObject);
procedure Edit3Exit(Sender: TObject);
procedure SpinImageChange(Sender: TObject; ItemIndex: Integer);
procedure FormCreate(Sender: TObject);
procedure bHelpClick(Sender: TObject);
private
public
end;
function AutoSpinImageItemsPropEditor(Control : TAutoCustomSpinImage) : Boolean;
implementation
uses autostrs;
function AutoSpinImageItemsPropEditor(Control : TAutoCustomSpinImage) : Boolean;
Var
Form : TFAutoSpinImagePropEditor;
Item : TAutoSpinImageItem;
i : Integer;
begin
Result := False;
Form := TFAutoSpinImagePropEditor.Create(Nil);
Form.Caption := Form.Caption + Control.Name;
Form.ListBox.ImageList := Control.ImageList;
Form.SpinImage.ImageList := Control.ImageList;
for i := 0 to Control.Items.Count - 1 do begin
Form.ListBox.AddItem(Control.Items[i].Value, Control.Items[i].ImageIndex);
Form.ListBox.Values[i] := Control.Items[i].Hint;
end;
Form.SpinImage.ItemIndex := -1;
if(Form.ListBox.Items.Count > 0) then
Form.ListBox.ItemIndex := 0;
Form.ListBoxClick(Nil);
Form.ShowModal;
if(Form.ModalResult = mrOk) then begin
Control.Items.Clear;
for i := 0 to Form.ListBox.Items.Count - 1 do begin
Item := Control.Items.Add;
with Form.ListBox do begin
Item.ImageIndex := ImageIndexes[i];
Item.Value := Items[i];
Item.Hint := Values[i];
end;
end;
Result := True;
end;
Form.Free;
end;
{$R *.DFM}
procedure TFAutoSpinImagePropEditor.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if((Key < '0') Or (Key > '9')) And (Key <> Char(VK_BACK))
And ((Key <> '-') Or ((Edit2.Text <> '') And (Edit2.Text <> Edit2.SelText))) then begin
Key := #0;
MessageBeep(0);
end;
end;
procedure TFAutoSpinImagePropEditor.Edit2Exit(Sender: TObject);
begin
if(ListBox.ItemIndex > -1) and (ListBox.Items.Count > 0) then begin
if(Edit2.Text = '-') then
Edit2.Text := '-1';
SpinImage.ItemIndex := StrToInt(Edit2.Text);
ListBox.ImageIndexes[ListBox.ItemIndex] := SpinImage.ItemIndex;
end;
end;
procedure TFAutoSpinImagePropEditor.bAddClick(Sender: TObject);
begin
ListBox.AddItem(IntToStr(ListBox.Items.Count), -1);
ListBox.ItemIndex := ListBox.Items.Count - 1;
ListBoxClick(Sender);
Edit2.SetFocus;
end;
procedure TFAutoSpinImagePropEditor.bInsertClick(Sender: TObject);
begin
if(ListBox.ItemIndex > -1) and (ListBox.Items.Count > 0) then begin
ListBox.InsertItem(ListBox.ItemIndex - 1, 'New Item', -1);
ListBoxClick(Sender);
Edit2.SetFocus;
end
else bAddClick(Sender);
end;
procedure TFAutoSpinImagePropEditor.bDeleteClick(Sender: TObject);
Var
index : Integer;
begin
if(ListBox.ItemIndex > -1) and (ListBox.Items.Count > 0) then begin
index := ListBox.ItemIndex;
ListBox.Items.Delete(ListBox.ItemIndex);
if(index < ListBox.Items.Count) then
ListBox.ItemIndex := index
else if (index > 0) then
ListBox.ItemIndex := index - 1;
ListBoxClick(Sender);
end;
end;
procedure TFAutoSpinImagePropEditor.Edit1Exit(Sender: TObject);
Var
index, imindex : Integer;
St : String;
begin
if(Edit1.Text <> ListBox.Items[ListBox.ItemIndex]) then begin
St := Edit1.Text;
imindex := ListBox.ImageIndexes[ListBox.ItemIndex];
index := ListBox.ItemIndex;
ListBox.Items.Delete(index);
ListBox.InsertItem(index, St, imindex);
ListBox.ItemIndex := index;
end;
end;
type
TtempAutoImageListBox = class(TAutoImageListBox)
public
property Values;
end;
procedure TFAutoSpinImagePropEditor.ListBoxClick(Sender: TObject);
begin
Edit1.Enabled := (ListBox.ItemIndex > -1) and (ListBox.Items.Count > 0);
Edit2.Enabled := Edit1.Enabled;
SpinImage.Enabled := Edit1.Enabled;
bDelete.Enabled := Edit1.Enabled;
bUp.Enabled := Edit1.Enabled;
bDown.Enabled := Edit1.Enabled;
Edit3.Enabled := Edit1.Enabled;
if(Edit1.Enabled) then begin
Edit1.Text := ListBox.Items[ListBox.ItemIndex];
Edit2.Text := IntToStr(ListBox.ImageIndexes[ListBox.ItemIndex]);
SpinImage.ItemIndex := ListBox.ImageIndexes[ListBox.ItemIndex];
Edit3.Text := TtempAutoImageListBox(ListBox).Values[ListBox.ItemIndex];
end else begin
Edit1.Text := '';
Edit2.Text := '';
Edit3.TExt := '';
SpinImage.ItemIndex := -1;
end;
end;
procedure TFAutoSpinImagePropEditor.bUpClick(Sender: TObject);
Var
index, imind1, imind2 : Integer;
begin
if(ListBox.ItemIndex > 0) then begin
index := ListBox.ItemIndex;
imind1 := ListBox.ImageIndexes[index];
imind2 := ListBox.ImageIndexes[index - 1];
ListBox.Items.Exchange(index, index - 1);
ListBox.ImageIndexes[index - 1] := imind1;
ListBox.ImageIndexes[index] := imind2;
ListBox.ItemIndex := index - 1;
end;
end;
procedure TFAutoSpinImagePropEditor.bDownClick(Sender: TObject);
Var
index, imind1, imind2 : Integer;
begin
if(ListBox.ItemIndex < ListBox.Items.Count - 1) then begin
index := ListBox.ItemIndex;
imind1 := ListBox.ImageIndexes[index];
imind2 := ListBox.ImageIndexes[index + 1];
ListBox.Items.Exchange(index, index + 1);
ListBox.ImageIndexes[index + 1] := imind1;
ListBox.ImageIndexes[index] := imind2;
ListBox.ItemIndex := index + 1;
end;
end;
procedure TFAutoSpinImagePropEditor.ListBoxDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
Var
p : TPoint;
item : Integer;
begin
Accept := False;
p.x := X;
p.y := Y;
item := ListBox.ItemAtPos(p, True);
if(item > -1) And (item < ListBox.Items.Count) then
Accept := Not ListBox.Selected[Item];
end;
procedure TFAutoSpinImagePropEditor.ListBoxDragDrop(Sender, Source: TObject; X,
Y: Integer);
Var
p : TPoint;
Item, Item1 : Integer;
flag : Boolean;
begin
ListBoxDragOver(Sender, Source, X, Y, dsDragLeave, flag);
if Not flag then exit;
p.x := X;
p.y := Y;
item := ListBox.ItemAtPos(p, True);
if(item > -1) And (item < ListBox.Items.Count) then begin
if(Item > ListBox.ItemIndex) then
Inc(Item);
ListBox.InsertItem(Item, ListBox.Items[ListBox.ItemIndex],
ListBox.ImageIndexes[ListBox.ItemIndex]);
item1 := ListBox.ItemIndex;
ListBox.Items.Delete(Item1);
if(Item >= Item1) then
Dec(Item);
ListBox.ItemIndex := Item;
end;
end;
procedure TFAutoSpinImagePropEditor.bClearClick(Sender: TObject);
begin
ListBox.Items.Clear;
ListBoxClick(Sender);
end;
procedure TFAutoSpinImagePropEditor.Edit3Exit(Sender: TObject);
begin
if(ListBox.ItemIndex > -1) and (ListBox.Items.Count > 0)
and (Edit3.Text <> TtempAutoImageListBox(ListBox).Values[ListBox.ItemIndex]) then
TtempAutoImageListBox(ListBox).Values[ListBox.ItemIndex] := Edit3.Text;
end;
procedure TFAutoSpinImagePropEditor.SpinImageChange(Sender: TObject;
ItemIndex: Integer);
begin
if(ListBox.ItemIndex > -1) and (ListBox.Items.Count > 0) then begin
Edit2.Text := IntToStr(ItemIndex);
Edit2Exit(Sender);
end;
end;
procedure TFAutoSpinImagePropEditor.FormCreate(Sender: TObject);
begin
Caption := LoadStr(AEC_SPINIMAGE_ITEMS);
bAdd.Caption := LoadStr(AEB_ADD);
bInsert.Caption := LoadStr(AEB_INSERT);
bDelete.Caption := LoadStr(AEB_DELETE);
bClear.Caption := LoadStr(AEB_CLEAR);
bUp.Caption := LoadStr(AEB_UP);
bDown.Caption := LoadStr(AEB_DOWN);
LabelHint.Caption := LoadStr(AEL_HINT);
LabelValue.Caption := LoadStr(AEL_VALUE);
LabelImageIndex.Caption := LoadStr(AEL_IMAGEINDEX);
BOk.Caption := LoadStr(ACB_OK);
bCancel.Caption := LoadStr(ACB_CANCEL);
bHelp.Caption := LoadStr(ACB_HELP);
end;
procedure TFAutoSpinImagePropEditor.bHelpClick(Sender: TObject);
begin
Application.HelpFile := 'aob_ps.hlp';
Application.HelpContext(10002);
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?