aimpredt.pas

来自「delphi编程控件」· PAS 代码 · 共 296 行

PAS
296
字号
unit aimpredt;
(*
 COPYRIGHT (c) RSD Software 1997 - 98
 All Rights Reserved.
*)

interface
           
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, AImCtrls;

type
  TFAutoImagePropEditor = class(TForm)
    Panel1: TPanel;
    bAdd: TButton;
    bInsert: TButton;
    bDelete: TButton;
    Panel2: TPanel;
    Panel3: TPanel;
    Edit1: TEdit;
    ListBox: TAutoImageListBox;
    bUp: TButton;
    bDown: TButton;
    LabelText: TLabel;
    bClear: TButton;
    LabelValue: TLabel;
    Edit3: TEdit;
    LabelImageIndex: TLabel;
    Edit2: TEdit;
    BOk: TButton;
    bCancel: TButton;
    bHelp: TButton;
    SpinImage: TAutoSpinImage;
    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 AutoImageItemsPropEditor(Control : TWinControl) : Boolean;


implementation
uses autostrs;

function AutoImageItemsPropEditor(Control : TWinControl) : Boolean;
Var
  Form : TFAutoImagePropEditor;
begin
  Result := False;
  Form := TFAutoImagePropEditor.Create(Nil);
  Form.Caption := Form.Caption + Control.Name;
  if(Control is TAutoCustomImageListBox) then
    Form.ListBox.Assign(TAutoCustomImageListBox(Control));
  if(Control is TAutoImageComboBox) then
    Form.ListBox.Assign(TAutoImageComboBox(Control));
  Form.Edit3.Visible := True;
  Form.LabelValue.Visible := True;
  Form.SpinImage.ImageList := Form.ListBox.ImageList;
  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
    if(Control is TAutoCustomImageListBox) then
      TAutoCustomImageListBox(Control).Assign(Form.ListBox);
    if(Control is TAutoImageComboBox) then
      TAutoImageComboBox(Control).Assign(Form.ListBox);
    Result := True;
  end;
  Form.Free;
end;

{$R *.DFM}

procedure TFAutoImagePropEditor.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 TFAutoImagePropEditor.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 TFAutoImagePropEditor.bAddClick(Sender: TObject);
begin
  ListBox.AddItem(LoadStr(AEL_NEWITEM), -1);
  ListBox.ItemIndex := ListBox.Items.Count - 1;
  ListBoxClick(Sender);
  Edit1.SetFocus;
end;

procedure TFAutoImagePropEditor.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);
    Edit1.SetFocus;    
  end
  else bAddClick(Sender);
end;

procedure TFAutoImagePropEditor.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 TFAutoImagePropEditor.Edit1Exit(Sender: TObject);
Var
  index, imindex : Integer;
  St : String;
begin
  if (ListBox.Items.Count > 0)
  and (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 TFAutoImagePropEditor.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 TFAutoImagePropEditor.bUpClick(Sender: TObject);
Var
  index : Integer;
begin
  if(ListBox.ItemIndex > 0) and (ListBox.Items.Count > 0) then begin
    index := ListBox.ItemIndex;
    ListBox.ExchangeItems(index, index - 1);
    ListBox.ItemIndex := index - 1;
  end;
end;

procedure TFAutoImagePropEditor.bDownClick(Sender: TObject);
Var
  index : Integer;
begin
  if(ListBox.ItemIndex < ListBox.Items.Count - 1) then begin
    index := ListBox.ItemIndex;
    ListBox.ExchangeItems(index, index + 1);
    ListBox.ItemIndex := index + 1;
  end;
end;

procedure TFAutoImagePropEditor.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 TFAutoImagePropEditor.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 TFAutoImagePropEditor.bClearClick(Sender: TObject);
begin
  ListBox.Items.Clear;
  ListBoxClick(Sender);  
end;

procedure TFAutoImagePropEditor.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 TFAutoImagePropEditor.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 TFAutoImagePropEditor.FormCreate(Sender: TObject);
begin
  Caption := LoadStr(AEC_IMAGECONTROLS_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);
  LabelText.Caption := LoadStr(AEL_TEXT);
  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 TFAutoImagePropEditor.bHelpClick(Sender: TObject);
begin
  Application.HelpFile := 'aob_ps.hlp';
  Application.HelpContext(10001);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?