VrBitmapsDlg.pas
上传用户:hbszzs
上传日期:2008-08-20
资源大小:628k
文件大小:5k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {*****************************************************}
  2. {                                                     }
  3. {     Varian Component Workshop                       }
  4. {                                                     }
  5. {     Varian Software NL (c) 1996-2000                }
  6. {     All Rights Reserved                             }
  7. {                                                     }
  8. {*****************************************************}
  9. unit VrBitmapsDlg;
  10. interface
  11. uses
  12.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  13.   VrClasses, Buttons, StdCtrls, ExtCtrls, ExtDlgs, VrControls, VrButtons,
  14.   VrDeskTop;
  15. type
  16.   TVrBitmapListDialog = class(TForm)
  17.     Panel1: TPanel;
  18.     ListBox: TListBox;
  19.     SaveDialog: TSaveDialog;
  20.     OpenDialog: TOpenDialog;
  21.     OpenPictureDialog: TOpenPictureDialog;
  22.     VrShadowButton1: TVrShadowButton;
  23.     VrShadowButton2: TVrShadowButton;
  24.     VrShadowButton3: TVrShadowButton;
  25.     VrShadowButton4: TVrShadowButton;
  26.     VrShadowButton5: TVrShadowButton;
  27.     VrShadowButton6: TVrShadowButton;
  28.     VrShadowButton7: TVrShadowButton;
  29.     VrShadowButton8: TVrShadowButton;
  30.     VrShadowButton9: TVrShadowButton;
  31.     VrDeskTop1: TVrDeskTop;
  32.     procedure FormCreate(Sender: TObject);
  33.     procedure FormDestroy(Sender: TObject);
  34.     procedure ButtonAddClick(Sender: TObject);
  35.     procedure ListBoxDrawItem(Control: TWinControl; Index: Integer;
  36.       Rect: TRect; State: TOwnerDrawState);
  37.     procedure ButtonDeleteClick(Sender: TObject);
  38.     procedure ButtonClearClick(Sender: TObject);
  39.     procedure ButtonLoadClick(Sender: TObject);
  40.     procedure ButtonSaveClick(Sender: TObject);
  41.     procedure ButtonMoveUpClick(Sender: TObject);
  42.     procedure ButtonMoveDownClick(Sender: TObject);
  43.     procedure SpeedButton1Click(Sender: TObject);
  44.     procedure VrShadowButton9Click(Sender: TObject);
  45.   private
  46.     procedure BitmapsChanged(Sender: TObject);
  47.   public
  48.     Bitmaps: TVrBitmaps;
  49.   end;
  50. implementation
  51. {$R *.DFM}
  52. procedure TVrBitmapListDialog.FormCreate(Sender: TObject);
  53. begin
  54.   Bitmaps := TVrBitmaps.Create;
  55.   Bitmaps.OnChange := BitmapsChanged;
  56. end;
  57. procedure TVrBitmapListDialog.FormDestroy(Sender: TObject);
  58. begin
  59.   Bitmaps.Free;
  60. end;
  61. procedure TVrBitmapListDialog.ButtonAddClick(Sender: TObject);
  62. var
  63.   Bitmap: TBitmap;
  64. begin
  65.   if OpenPictureDialog.Execute then
  66.   begin
  67.     Bitmap := TBitmap.Create;
  68.     try
  69.       Bitmap.LoadFromFile(OpenPictureDialog.FileName);
  70.       Bitmaps.Add(Bitmap);
  71.     finally
  72.       Bitmap.Free;
  73.     end;
  74.   end;
  75. end;
  76. procedure TVrBitmapListDialog.ListBoxDrawItem(Control: TWinControl; Index: Integer;
  77.   Rect: TRect; State: TOwnerDrawState);
  78. var
  79.   ImgRect: TRect;
  80.   MidY: Integer;
  81.   S: string;
  82. begin
  83.   with TListBox(Control) do
  84.   begin
  85.     Canvas.FillRect(Rect);
  86.     ImgRect := Rect;
  87.     ImgRect.Right := 62;
  88.     OffsetRect(ImgRect, 2, 0);
  89.     InflateRect(ImgRect, 0, -2);
  90.     Canvas.StretchDraw(ImgRect, Bitmaps[Index]);
  91.     S := Format('%d - %d x %d', [Index, Bitmaps[Index].Width, Bitmaps[Index].Height]);
  92.     MidY := ((Rect.Bottom - Rect.Top) - Canvas.TextHeight(S)) div 2;
  93.     Canvas.TextOut(ImgRect.Right + 20, Rect.Top + MidY, S);
  94.   end;
  95. end;
  96. procedure TVrBitmapListDialog.ButtonDeleteClick(Sender: TObject);
  97. var
  98.   Index: Integer;
  99. begin
  100.   Index := ListBox.ItemIndex;
  101.   if Index <> -1 then
  102.     Bitmaps.Delete(Index);
  103. end;
  104. procedure TVrBitmapListDialog.ButtonClearClick(Sender: TObject);
  105. begin
  106.   if MessageDlg('Clear list?', mtConfirmation,
  107.     [mbOk, mbCancel], 0) = mrOk then Bitmaps.Clear;
  108. end;
  109. procedure TVrBitmapListDialog.ButtonLoadClick(Sender: TObject);
  110. begin
  111.   if OpenDialog.Execute then
  112.     Bitmaps.LoadFromFile(OpenDialog.FileName);
  113. end;
  114. procedure TVrBitmapListDialog.ButtonSaveClick(Sender: TObject);
  115. begin
  116.   if SaveDialog.Execute then
  117.     Bitmaps.SaveToFile(SaveDialog.FileName);
  118. end;
  119. procedure TVrBitmapListDialog.ButtonMoveUpClick(Sender: TObject);
  120. var
  121.   Index: Integer;
  122. begin
  123.   Index := ListBox.ItemIndex;
  124.   if Index - 1 >= 0 then
  125.   begin
  126.     Bitmaps.Move(Index, Index - 1);
  127.     ListBox.ItemIndex := Index - 1;
  128.   end;
  129. end;
  130. procedure TVrBitmapListDialog.ButtonMoveDownClick(Sender: TObject);
  131. var
  132.   Index: Integer;
  133. begin
  134.   Index := ListBox.ItemIndex;
  135.   if (Index <> -1) and (Index + 1 < ListBox.Items.Count) then
  136.   begin
  137.     Bitmaps.Move(Index, Index + 1);
  138.     ListBox.ItemIndex := Index + 1;
  139.   end;
  140. end;
  141. procedure TVrBitmapListDialog.SpeedButton1Click(Sender: TObject);
  142. begin
  143.   ModalResult := mrOk;
  144. end;
  145. procedure TVrBitmapListDialog.BitmapsChanged(Sender: TObject);
  146. var
  147.   I: Integer;
  148. begin
  149.   ListBox.Items.BeginUpdate;
  150.   try
  151.     ListBox.Items.Clear;
  152.     for I := 0 to Bitmaps.Count - 1 do
  153.       ListBox.Items.Add('XXX');
  154.   finally
  155.     ListBox.Items.EndUpdate;
  156.   end;
  157. end;
  158. procedure TVrBitmapListDialog.VrShadowButton9Click(Sender: TObject);
  159. begin
  160.   ModalResult := mrCancel;
  161. end;
  162. end.