NBPagesEditor.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:5k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {*******************************************************************}
  2. {                                                                   }
  3. {       Almediadev Visual Component Library                         }
  4. {       BusinessSkinForm                                            }
  5. {       Version 2.90                                                }
  6. {                                                                   }
  7. {       Copyright (c) 2000-2004 Almediadev                          }
  8. {       ALL RIGHTS RESERVED                                         }
  9. {                                                                   }
  10. {       Home:  http://www.almdev.com                                }
  11. {       Support: support@almdev.com                                 }
  12. {                                                                   }
  13. {*******************************************************************}
  14. unit NBPagesEditor;
  15. interface
  16. uses
  17.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  18.   bsSkinCtrls, StdCtrls;
  19. type
  20.   TNBPagesForm = class(TForm)
  21.     PageListBox: TListBox;
  22.     CaptionEdit: TEdit;
  23.     AddButton: TButton;
  24.     DeleteButton: TButton;
  25.     MoveUpButton: TButton;
  26.     MoveDownButton: TButton;
  27.     IIndexBox: TComboBox;
  28.     Label1: TLabel;
  29.     procedure FormShow(Sender: TObject);
  30.     procedure AddButtonClick(Sender: TObject);
  31.     procedure DeleteButtonClick(Sender: TObject);
  32.     procedure PageListBoxClick(Sender: TObject);
  33.     procedure CaptionEditChange(Sender: TObject);
  34.     procedure MoveUpButtonClick(Sender: TObject);
  35.     procedure MoveDownButtonClick(Sender: TObject);
  36.     procedure IIndexBoxChange(Sender: TObject);
  37.   private
  38.     NB: TbsSkinNoteBook;
  39.   public
  40.     { Public declarations }
  41.   end;
  42. var
  43.   NBPagesForm: TNBPagesForm;
  44.   procedure Execute(ANoteBook: TbsSkinNoteBook);
  45. implementation
  46. {$R *.DFM}
  47. procedure Execute(ANoteBook: TbsSkinNoteBook);
  48. begin
  49.   NBPagesForm := TNBPagesForm.Create(Application);
  50.   NBPagesForm.NB := ANoteBook;
  51.   NBPagesForm.ShowModal;
  52.   NBPagesForm.Free;
  53. end;
  54. procedure TNBPagesForm.FormShow(Sender: TObject);
  55. var
  56.   I, J: Integer;
  57. begin
  58.   if NB.Pages.Count <> 0
  59.   then
  60.     begin
  61.       for I := 0 to NB.Pages.Count - 1 do
  62.       PageListBox.Items.Add(NB.Pages[I]);
  63.       PageListBox.ItemIndex := 0;
  64.       CaptionEdit.Text := PageListBox.Items[PageListBox.ItemIndex];
  65.     end;
  66.   IIndexBox.Clear;
  67.   if NB.Images <> nil
  68.   then
  69.     for I := -1 to NB.Images.Count - 1 do
  70.     begin
  71.       IIndexBox.Items.Add(IntToStr(I));
  72.       J := TbsSkinPage(NB.FPageList.Items[PageListBox.ItemIndex]).ImageIndex;
  73.       IIndexBox.ItemIndex := J + 1;
  74.     end;
  75. end;
  76. procedure TNBPagesForm.AddButtonClick(Sender: TObject);
  77. begin
  78.   NB.Pages.Add('Page' + IntToStr(NB.Pages.Count));
  79.   PageListBox.Items.Add(NB.Pages[NB.Pages.Count - 1]);
  80.   PageListBox.ItemIndex := NB.Pages.Count - 1;
  81. end;
  82. procedure TNBPagesForm.DeleteButtonClick(Sender: TObject);
  83. begin
  84.   NB.Pages.Delete(PageListBox.ItemIndex);
  85.   PageListBox.Items.Delete(PageListBox.ItemIndex);
  86. end;
  87. procedure TNBPagesForm.PageListBoxClick(Sender: TObject);
  88. begin
  89.   if PageListBox.ItemIndex <> -1
  90.   then
  91.     begin
  92.       CaptionEdit.Text := PageListBox.Items[PageListBox.ItemIndex];
  93.       NB.PageIndex := PageListBox.ItemIndex;
  94.       IIndexBox.ItemIndex := TbsSkinPage(NB.FPageList.Items[PageListBox.ItemIndex]).ImageIndex + 1;
  95.     end;
  96. end;
  97. procedure TNBPagesForm.CaptionEditChange(Sender: TObject);
  98. begin
  99.   with PageListBox do
  100.   if ItemIndex <> -1
  101.   then
  102.     begin
  103.       NB.Pages[ItemIndex] := CaptionEdit.Text;
  104.       Items[ItemIndex] := NB.Pages[ItemIndex];
  105.     end;
  106. end;
  107. procedure TNBPagesForm.MoveUpButtonClick(Sender: TObject);
  108. var
  109.   I: Integer;
  110. begin
  111.   with PageListBox do
  112.   if (ItemIndex <> -1) and (ItemIndex > 0)
  113.   then
  114.     begin
  115.       I := ItemIndex;
  116.       NB.Pages.Move(ItemIndex, ItemIndex - 1);
  117.       Items.Move(ItemIndex, ItemIndex - 1);
  118.       ItemIndex := I - 1;
  119.       CaptionEdit.Text := PageListBox.Items[PageListBox.ItemIndex];
  120.       NB.PageIndex := ItemIndex;
  121.     end;
  122. end;
  123. procedure TNBPagesForm.MoveDownButtonClick(Sender: TObject);
  124. var
  125.   I: Integer;
  126. begin
  127.   with PageListBox do
  128.   if (ItemIndex <> -1) and (ItemIndex < NB.Pages.Count - 1)
  129.   then
  130.     begin
  131.       I := ItemIndex;
  132.       NB.Pages.Move(ItemIndex, ItemIndex + 1);
  133.       Items.Move(ItemIndex, ItemIndex + 1);
  134.       ItemIndex := I + 1;
  135.       CaptionEdit.Text := PageListBox.Items[PageListBox.ItemIndex];
  136.       NB.PageIndex := ItemIndex;
  137.     end;
  138. end;
  139. procedure TNBPagesForm.IIndexBoxChange(Sender: TObject);
  140. var
  141.   Form: TCustomForm;
  142. begin
  143.   if PageListBox.ItemIndex = -1 then Exit;
  144.   TbsSkinPage(NB.FPageList.Items[PageListBox.ItemIndex]).ImageIndex := IIndexBox.ItemIndex - 1;
  145.   NB.UpDateButton(PageListBox.ItemIndex, PageListBox.Items[PageListBox.ItemIndex]);
  146.   if csDesigning in NB.ComponentState then
  147.   begin
  148.     Form := GetParentForm(NB);
  149.     if (Form <> nil) and (Form.Designer <> nil) then
  150.       Form.Designer.Modified;
  151.   end;
  152. end;
  153. end.