程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 設置ListView的頁眉圖標

設置ListView的頁眉圖標

編輯:Delphi
(*//
標題:設置ListVIEw的頁眉圖標
說明:可以用來做排序修飾圖標
設計:Zswang
支持:[email protected]
日期:2004-03-25
//*)
uses CommCtrl;
function ListViewHeaderImages(mListView: TListView; mImages: TImageList): Boolean;
var
  vHandle: THandle;
begin
  Result := False;
  if not Assigned(mListView) then Exit;
  vHandle := ListView_GetHeader(mListView.Handle);
  if Assigned(mImages) then
    Header_SetImageList(vHandle, mImages.Handle)
  else Header_SetImageList(vHandle, 0);
  Result := True;
end; { ListVIEwHeaderImages }
function ListColumnImageIndex(mColumn: TListColumn;
  mImageIndex: Integer; mRight: Boolean = True): Boolean;
var
  vHandle: THandle;
  vHDItem: THDItem;
begin
  Result := False;
  if not Assigned(mColumn) then Exit;
  vHandle := ListView_GetHeader(TListVIEw(mColumn.Collection.Owner).Handle);
  FillChar(vHDItem, SizeOf(vHDItem), 0);
  Header_GetItem(vHandle, mColumn.Index, vHDItem);
  if mImageIndex < 0 then begin
    vHDItem.Mask := HDI_FORMAT;
    vHDItem.fmt := HDF_STRING;
  end else begin
    vHDItem.Mask := HDI_IMAGE or HDI_FORMAT;
    vHDItem.iImage := mImageIndex;
    vHDItem.fmt := HDF_STRING or HDF_IMAGE or
      (HDF_BITMAP_ON_RIGHT * Ord(mRight));
  end;
  Header_SetItem(vHandle, mColumn.Index, vHDItem);
end; { ListColumnImageIndex }
//Example
procedure TForm1.ListView1ColumnClick(Sender: TObject;
  Column: TListColumn);
{$J+}
const vIndex: Integer = 0;
{$J-}
var
  I: Integer;
begin
  for I := 0 to TListView(Sender).Columns.Count - 1 do
    ListColumnImageIndex(TListVIEw(Sender).Columns[I], -1);
  if Abs(vIndex) = Column.Index + 1 then
    vIndex := -vIndex
  else vIndex := Column.Index + 1;
  ListColumnImageIndex(Column, Ord(vIndex > 0));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
  ListViewHeaderImages(ListVIEw1, ImageList1);
end;
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved