全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:4180
推到 Plurk!
推到 Facebook!

關於ListView的column此行,如何修改字體,底色,文字顏色呢?

答題得分者是:RaynorPao
linda_wei
一般會員


發表:44
回覆:31
積分:20
註冊:2004-04-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-09-22 13:32:04 IP:220.132.xxx.xxx 訂閱
如題 ListView 的 Title行,如何修改字體,底色,文字顏色呢?
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-09-30 16:38:55 IP:210.208.xxx.xxx 訂閱
假設你的 ListView 有 3 個 Column,請參考以下的範例程式碼,自行修改

[code cpp]
// Unit1.h
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TListView *ListView1;
private: // User declarations
TWndMethod OldListViewWndProc;
void __fastcall NewListViewWndProc(TMessage &Msg);
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
[/code]

[code cpp]
// Unit1.cpp
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
HWND hHeader=GetDlgItem(ListView1->Handle, 0);
HDITEM hdi;
for(int j=0; jColumns->Count; j )
{
hdi.mask=HDI_FORMAT;
hdi.fmt=HDF_OWNERDRAW;
Header_SetItem(hHeader, j, &hdi);
}
OldListViewWndProc=ListView1->WindowProc;
ListView1->WindowProc=NewListViewWndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NewListViewWndProc(TMessage &Msg)
{
if(Msg.Msg==WM_DRAWITEM)
{
LPDRAWITEMSTRUCT lpdis=(DRAWITEMSTRUCT*)Msg.LParam;
HDC hdcHeader=lpdis->hDC;
RECT rcItem=lpdis->rcItem;
int iItem=lpdis->itemID;

TFont *HeaderFont=new TFont();
TBrush *HeaderBrush=new TBrush();
HeaderFont->Style=HeaderFont->Style<// HeaderFont->Name="標楷體";
HeaderFont->Name="細明體";
SelectObject(hdcHeader, HeaderFont->Handle);

switch(iItem)
{
case 0:
HeaderBrush->Color=clBlue;
::SetTextColor(hdcHeader, ColorToRGB(clYellow));
break;
case 1:
HeaderBrush->Color=clGreen;
::SetTextColor(hdcHeader, ColorToRGB(clRed));
break;
case 2:
HeaderBrush->Color=clBlack;
::SetTextColor(hdcHeader, ColorToRGB(clWhite));
break;
}
::FillRect(hdcHeader, &rcItem, HeaderBrush->Handle);
::SetBkMode(hdcHeader, TRANSPARENT);

AnsiString szText=ListView1->Columns->Items[iItem]->Caption;
::DrawText(hdcHeader, szText.c_str(), szText.Length(), &rcItem, DT_CENTER);
delete HeaderFont;
delete HeaderBrush;
Msg.Result=true;
}
else
{
OldListViewWndProc(Msg);
}
}
//---------------------------------------------------------------------------
[/code]
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
linda_wei
一般會員


發表:44
回覆:31
積分:20
註冊:2004-04-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-10-01 09:17:34 IP:220.132.xxx.xxx 訂閱
sorry, 我依上例做了,但是沒效果出來......... 
2007
中階會員


發表:54
回覆:90
積分:98
註冊:2008-08-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-10-01 09:38:44 IP:220.132.xxx.xxx 未訂閱

http://delphi.ktop.com.tw/download.php?download=upload/48e2d4653d267_ListView.rar

http://delphi.ktop.com.tw/board.php?cid=31&fid=97&tid=95464

我試可以耶!!!


===================引 用 linda_wei 文 章===================
sorry, 我依上例做了,但是沒效果出來.........
macchen
初階會員


發表:66
回覆:102
積分:33
註冊:2006-07-07

發送簡訊給我
#5 引用回覆 回覆 發表時間:2012-12-12 15:27:40 IP:219.87.xxx.xxx 訂閱
請問一下,我照著做是可以,但是為什麼一拉動header後顏色就不會變了,我是用在xe2,我在想是不是msg.msg這邊判斷要調整呢?謝謝。

===================引 用 2007 文 章===================

http://delphi.ktop.com.tw/download.php?download=upload/48e2d4653d267_ListView.rar

http://delphi.ktop.com.tw/board.php?cid=31&fid=97&tid=95464

我試可以耶!!!


===================引 用 linda_wei 文 章===================
sorry, 我依上例做了,但是沒效果出來.........
------
DELPHI初學者
系統時間:2024-04-24 18:14:38
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!