線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2669
推到 Plurk!
推到 Facebook!

請問一下有什麼類似 pagecontrol 但是可以指定顏色的元件

答題得分者是:pedro
black_eagle1028
一般會員


發表:8
回覆:7
積分:3
註冊:2007-05-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-07-05 12:26:41 IP:210.68.xxx.xxx 訂閱
請問一下有什麼類似 pagecontrol 但是可以指定顏色的元件, 我有利用 pagecontrol 的 tabsheet 放置多頁的頁面, 但是我發現每個 tabsheet 的顏色都跟 from 的底色一樣, 請問一下有辦法指定 tabsheet 或是 pagecontrol 的顏色嗎? 還是要用其他的元件才可以呢?
pedro
尊榮會員


發表:152
回覆:1187
積分:892
註冊:2002-06-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-07-05 12:33:37 IP:60.248.xxx.xxx 未訂閱
在TabSheet放置一個佔滿整個TabSheet的Panel
Panel即可自定顏色
kevin2004
資深會員


發表:18
回覆:463
積分:416
註冊:2005-05-29

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-07-05 21:32:43 IP:61.219.xxx.xxx 訂閱
小弟也有個類似的問題。
在TabSheet上加Panel設顏色,只能在此TabSheet主體才有顏色,但它的頁標頭就沒顏色了。而我要的是這個頁標頭要有顏色,那要怎麼辦?
而如果一個PageControl有好幾頁,每有頁上都有一個DBMemo,那我要如何在有資料的TabSheet的頁標要有顏色,以便提醒User翻看此TabSheet,這要如何作。
------
Kevin
編輯記錄
kevin2004 重新編輯於 2007-07-05 21:35:06, 註解 無‧
pedro
尊榮會員


發表:152
回覆:1187
積分:892
註冊:2002-06-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-07-05 23:15:02 IP:59.112.xxx.xxx 未訂閱
是有可能的,向VCL挖寶吧
PageControl.OwnerDraw設True,就會觸發PageControl1DrawTab()這個事件
然後向TabSheet.WMNCPaint動手術

注意這幾行,我加進去的
DC := GetWindowDC(Handle);
Brush.Color:=clSkyBlue;
try
.
.
Control.Canvas.Brush.Color:=clSkyBlue;
if Active then
Control.Canvas.Font.Style := [fsBold]
else
Control.Canvas.Font.Style := [];


<textarea class="delphi" rows="10" cols="60" name="code">type TForm1 = class(TForm) Button1: TButton; PageControl1: TPageControl; procedure Button1Click(Sender: TObject); procedure PageControl1DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean); private { Private declarations } public { Public declarations } end; TFoolSheet=class(TTabSheet) protected procedure WMNCPaint(var Message: TWMNCPaint); message WM_NCPAINT; end; var Form1: TForm1; implementation {$R *.dfm} uses CommCtrl; { TFoolSheet } procedure TFoolSheet.WMNCPaint(var Message: TWMNCPaint); const InnerStyles: array[TBevelCut] of Integer = (0, BDR_SUNKENINNER, BDR_RAISEDINNER, 0); OuterStyles: array[TBevelCut] of Integer = (0, BDR_SUNKENOUTER, BDR_RAISEDOUTER, 0); EdgeStyles: array[TBevelKind] of Integer = (0, 0, BF_SOFT, BF_FLAT); Ctl3DStyles: array[Boolean] of Integer = (BF_MONO, 0); var DC: HDC; RC, RW, SaveRW: TRect; EdgeSize: Integer; WinStyle: Longint; begin { Get window DC that is clipped to the non-client area } if (BevelKind <> bkNone) or (BorderWidth > 0) then begin DC := GetWindowDC(Handle); Brush.Color:=clSkyBlue; try Windows.GetClientRect(Handle, RC); GetWindowRect(Handle, RW); MapWindowPoints(0, Handle, RW, 2); OffsetRect(RC, -RW.Left, -RW.Top); ExcludeClipRect(DC, RC.Left, RC.Top, RC.Right, RC.Bottom); { Draw borders in non-client area } SaveRW := RW; InflateRect(RC, BorderWidth, BorderWidth); RW := RC; if BevelKind <> bkNone then begin EdgeSize := 0; if BevelInner <> bvNone then Inc(EdgeSize, BevelWidth); if BevelOuter <> bvNone then Inc(EdgeSize, BevelWidth); with RW do begin WinStyle := GetWindowLong(Handle, GWL_STYLE); if beLeft in BevelEdges then Dec(Left, EdgeSize); if beTop in BevelEdges then Dec(Top, EdgeSize); if beRight in BevelEdges then Inc(Right, EdgeSize); if (WinStyle and WS_VSCROLL) <> 0 then Inc(Right, GetSystemMetrics(SM_CYVSCROLL)); if beBottom in BevelEdges then Inc(Bottom, EdgeSize); if (WinStyle and WS_HSCROLL) <> 0 then Inc(Bottom, GetSystemMetrics(SM_CXHSCROLL)); end; DrawEdge(DC, RW, InnerStyles[BevelInner] or OuterStyles[BevelOuter], Byte(BevelEdges) or EdgeStyles[BevelKind] or Ctl3DStyles[Ctl3D] or BF_ADJUST); end; IntersectClipRect(DC, RW.Left, RW.Top, RW.Right, RW.Bottom); RW := SaveRW; { Erase parts not drawn } OffsetRect(RW, -RW.Left, -RW.Top); Windows.FillRect(DC, RW, Brush.Handle); finally ReleaseDC(Handle, DC); end; end; inherited; end; procedure TForm1.Button1Click(Sender: TObject); var page1,page2:TFoolSheet; begin page1:=TFoolSheet.Create(self); page1.Caption:='page1'; page1.PageControl:=PageControl1; page1.BevelKind:=bkTile; page2:=TFoolSheet.Create(self); page2.Caption:='page2'; page2.PageControl:=PageControl1; page2.BevelKind:=bkTile; end; procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean); var aRect: TRect; i, ti, ind: Integer; begin Control.Canvas.Brush.Color:=clSkyBlue; if Active then Control.Canvas.Font.Style := [fsBold] else Control.Canvas.Font.Style := []; aRect := Rect; OffSetRect(aRect,0,4); ti := -1; ind := TabIndex; for i := 0 to PageControl1.PageCount - 1 do begin if ti = TabIndex then Break; if not PageControl1.Pages[i].TabVisible then Inc(ind) else Inc(ti); end; DrawText(Control.Canvas.Handle,PChar(PageControl1.Pages[ind].Caption), -1,aRect,DT_CENTER or DT_SINGLELINE); end; </textarea>
編輯記錄
 重新編輯於 2007-07-05 23:18:26, 註解 無‧
kevin2004
資深會員


發表:18
回覆:463
積分:416
註冊:2005-05-29

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-07-06 08:01:10 IP:61.219.xxx.xxx 訂閱
想之久矣,大喜過望,小弟拜謝。
小弟寫了好幾個都有N個Memo欄位的應用,如文獻管理、知識經驗管理、工作日誌等的小東西,正須此等貼心功能。
謝謝前輩指點。拜謝,拜謝。
------
Kevin
編輯記錄
kevin2004 重新編輯於 2007-07-06 08:02:21, 註解 無‧
系統時間:2024-07-02 8:45:35
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!