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

關於TabSheet的顏色~~

尚未結案
aresu
一般會員


發表:14
回覆:14
積分:5
註冊:2004-07-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-07-28 11:40:20 IP:220.130.xxx.xxx 未訂閱
在TabSheet的Caption那邊變色的方法我已經在站上找到~~感謝~~ 可是TabSheet裡要怎麼變色~~? 在TabSheet裡貼個Panel然後指定Panel的顏色這一招改變不到框的顏色~~ 也許我想要的像這樣~~ http://delphi.ktop.com.tw/topic.php?topic_id=40082 那張圖看起來連框都有黃色~~?
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-07-28 13:45:07 IP:202.39.xxx.xxx 未訂閱
參考這篇看看 "change the color of a TPageControls" http://www.swissdelphicenter.ch/en/showcode.php?id=788:
type 
  TTabSheet = class(ComCtrls.TTabSheet) 
  private 
    FColor: TColor; 
    procedure SetColor(Value: TColor); 
    procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd); 
      message WM_ERASEBKGND; 
  public 
    constructor Create(aOwner: TComponent); override; 
    property Color: TColor read FColor write SetColor; 
  end;     type 
  TForm1 = class(TForm) 
    Button1: TButton; 
    PageControl1: TPageControl; 
    TabSheet1: TTabSheet; 
    TabSheet2: TTabSheet; 
    TabSheet3: TTabSheet; 
    procedure PageControl1DrawTab(Control: TCustomTabControl; 
      TabIndex: Integer; const Rect: TRect; Active: Boolean); 
    procedure FormCreate(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end;     var 
  Form1: TForm1;     implementation     {$R *.dfm}     constructor TTabSheet.Create(aOwner: TComponent); 
begin 
  inherited; 
  FColor := clBtnFace; 
end;     procedure TTabSheet.SetColor(Value: TColor); 
begin 
  if FColor <> Value then 
  begin 
    FColor := Value; 
    Invalidate; 
  end; 
end;     procedure TTabSheet.WMEraseBkGnd(var Msg: TWMEraseBkGnd); 
begin 
  if FColor = clBtnFace then 
    inherited 
  else 
  begin 
    Brush.Color := FColor; 
    Windows.FillRect(Msg.dc, ClientRect, Brush.Handle); 
    Msg.Result := 1; 
  end; 
end;     procedure TForm1.FormCreate(Sender: TObject); 
begin 
  Tabsheet1.Color := clWhite; 
  TabSheet2.Color := clLime; 
end;     // PageControl1.OwnerDraw := True !     procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl; 
  TabIndex: Integer; const Rect: TRect; Active: Boolean); 
var 
  AText: string; 
  APoint: TPoint; 
begin 
  with (Control as TPageControl).Canvas do 
  begin 
    Brush.Color := ClGreen; 
    FillRect(Rect); 
    AText := TPageControl(Control).Pages[TabIndex].Caption; 
    with Control.Canvas do 
    begin 
      APoint.x := (Rect.Right - Rect.Left) div 2 - TextWidth(AText) div 2; 
      APoint.y := (Rect.Bottom - Rect.Top) div 2 - TextHeight(AText) div 2; 
      TextRect(Rect, Rect.Left   APoint.x, Rect.Top   APoint.y, AText); 
    end; 
  end; 
end;     end.
-- 向 KTop 的弟兄們致敬!
aresu
一般會員


發表:14
回覆:14
積分:5
註冊:2004-07-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-07-28 15:05:25 IP:220.130.xxx.xxx 未訂閱
感謝版大的回應~~ 但我試做時TabSheet的框還是一樣的顏色~~並沒有如 http://www.swissdelphicenter.ch/en/showcode.php?id=788: 的效果~~ 請不吝再指教一次~~
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-07-28 16:00:49 IP:202.39.xxx.xxx 未訂閱
您要的是紅色的部份?
procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl; 
  TabIndex: Integer; const Rect: TRect; Active: Boolean); 
var 
  AText: string; 
  APoint: TPoint; 
begin 
  with (Control as TPageControl).Canvas do 
  begin 
    Brush.Color := ClGreen; 
    FillRect(Rect); 
    AText := TPageControl(Control).Pages[TabIndex].Caption; 
    with Control.Canvas do 
    begin 
      APoint.x := (Rect.Right - Rect.Left) div 2 - TextWidth(AText) div 2; 
      APoint.y := (Rect.Bottom - Rect.Top) div 2 - TextHeight(AText) div 2; 
      TextRect(Rect, Rect.Left   APoint.x, Rect.Top   APoint.y, AText); 
    end; 

    Pen.Color := clRed;
    Pen.Width := 3;
    MoveTo(Rect.Left   1, Rect.Top   1);
    LineTo(Rect.Left   1, Rect.Top   (Rect.Bottom - Rect.Top) - 1);
    MoveTo(Rect.Left   1, Rect.Top   1);
    LineTo(Rect.Left   (Rect.Right - Rect.Left) - 1, Rect.Top   1);
    MoveTo(Rect.Left   (Rect.Right - Rect.Left) - 1, Rect.Top   1);
    LineTo(Rect.Left   (Rect.Right - Rect.Left) - 1, Rect.Top   (Rect.Bottom - Rect.Top) - 1);
    MoveTo(Rect.Left   1, Rect.Top   (Rect.Bottom - Rect.Top) - 1);
    LineTo(Rect.Left   (Rect.Right - Rect.Left) - 1, Rect.Top   (Rect.Bottom - Rect.Top) - 1);      end; 
end; 
-- 向 KTop 的弟兄們致敬!
aresu
一般會員


發表:14
回覆:14
積分:5
註冊:2004-07-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-07-28 16:21:35 IP:220.130.xxx.xxx 未訂閱
sorry~~我資質不好~~ Pen和MoveTo那些我Compile不能過~~ 是不是要uses什麼~~?或在哪裡宣告~~?
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-07-28 16:34:44 IP:202.39.xxx.xxx 未訂閱
錯誤訊息是什麼? 照理來說 Graphics 這個 unit 是預設就有 uses 的啊!    -- 向 KTop 的弟兄們致敬! 
aresu
一般會員


發表:14
回覆:14
積分:5
註冊:2004-07-13

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-07-28 16:49:59 IP:220.130.xxx.xxx 未訂閱
抱歉~~老是麻煩您~~ 之前我自己犯了嚴重的錯誤~~不是您的問題~~ 在此跟您道歉~~ 不過我所謂的框不是指上面Caption那邊的框~~是指下面整個TabSheet的框~~ 呃~~這樣講您聽的懂嗎~~?
aresu
一般會員


發表:14
回覆:14
積分:5
註冊:2004-07-13

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-07-28 16:56:39 IP:220.130.xxx.xxx 未訂閱
sorry~~補充一下~~ 如果在TabSheet貼個Panel然後再指定Panel的顏色~~ 就會很明顯看到Panel的外面有框~~ 我現在希望連那個框也可以變色~~ sorry~~表達能力太差~~
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#9 引用回覆 回覆 發表時間:2004-07-28 17:48:25 IP:202.39.xxx.xxx 未訂閱
不嫌麻煩的話, 用個圖出來看看!  -- 向 src="http://www.sweetbaby.net/~hagar/good.bmp">
aresu
一般會員


發表:14
回覆:14
積分:5
註冊:2004-07-13

發送簡訊給我
#10 引用回覆 回覆 發表時間:2004-07-28 21:03:56 IP:203.74.xxx.xxx 未訂閱
在圖中是否會看到褐色區域的外圍像框一樣~~? 我需要的是"整個"TabSheet都能夠變色~~若有看到哪裡沒變的話都是不對滴~~ 只是TabSheet的Caption變色由於大家的分享我已經會了~~感恩~~ 感謝大家的指教喔~~ < src="http://delphi.ktop.com.tw/loadfile.php?TOPICID=16867583&CC=377237">
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#11 引用回覆 回覆 發表時間:2004-07-29 08:56:24 IP:202.39.xxx.xxx 未訂閱
在這篇 http://www.swissdelphicenter.ch/en/showcode.php?id=788 中 加入紅色的部份試試:
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Buttons, StdCtrls, ComCtrls, Mask, ExtCtrls;    type
  TTabSheet = class(ComCtrls.TTabSheet)
  private
    FColor: TColor;
    procedure SetColor(Value: TColor);
    procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd);
      message WM_ERASEBKGND;
  public
    constructor Create(aOwner: TComponent); override;
    property Color: TColor read FColor write SetColor;
  end;    type
  TForm1 = class(TForm)
    Button1: TButton;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    procedure FormCreate(Sender: TObject);
    procedure PageControl1DrawTab(Control: TCustomTabControl;
      TabIndex: Integer; const Rect: TRect; Active: Boolean);
    procedure PageControl1Change(Sender: TObject);
    procedure DrawTabSheetBorder;
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    {$R *.DFM}    { TTabSheet }    constructor TTabSheet.Create(aOwner: TComponent);
begin
  inherited;
  FColor := clBtnFace;
end;    procedure TTabSheet.SetColor(Value: TColor);
begin
  if FColor <> Value then
  begin
    FColor := Value;
    Invalidate;
  end;
end;    procedure TTabSheet.WMEraseBkGnd(var Msg: TWMEraseBkGnd);
begin
  if FColor = clBtnFace then
    inherited
  else
  begin
    Brush.Color := FColor;
    Windows.FillRect(Msg.dc, ClientRect, Brush.Handle);        Msg.Result := 1;
  end;
end;    { Form1 }    procedure TForm1.FormCreate(Sender: TObject);
begin
  Tabsheet1.Color := clWhite;
  TabSheet2.Color := clLime;
end;    procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  AText: string;
  APoint: TPoint;
begin
  with (Control as TPageControl).Canvas do
  begin
    Brush.Color := ClGreen;
    FillRect(Rect);
    AText := TPageControl(Control).Pages[TabIndex].Caption;
    with Control.Canvas do
    begin
      APoint.x := (Rect.Right - Rect.Left) div 2 - TextWidth(AText) div 2;
      APoint.y := (Rect.Bottom - Rect.Top) div 2 - TextHeight(AText) div 2;
      TextRect(Rect, Rect.Left   APoint.x, Rect.Top   APoint.y, AText);
    end;
  end;
  DrawTabSheetBorder;
end;    procedure TForm1.PageControl1Change(Sender: TObject);
begin
  DrawTabSheetBorder;
end;    procedure TForm1.DrawTabSheetBorder;
var
  Canvas: TCanvas;
  R: TRect;
begin
  Canvas := PageControl1.Canvas;
  R.Left := PageControl1.ClientRect.Left;
  R.Top := PageControl1.ClientRect.Bottom - PageControl1.Pages[PageControl1.ActivePageIndex].Height - 3;
  R.Right := PageControl1.ClientRect.Right;
  R.Bottom := PageControl1.ClientRect.Bottom;
  case PageControl1.ActivePageIndex of
    0: Canvas.Pen.Color := TabSheet1.Color;
    1: Canvas.Pen.Color := TabSheet2.Color;
  end;      Canvas.Pen.Width := 9;
  Canvas.MoveTo(R.Left, R.Top);
  Canvas.LineTo(R.Left, R.Bottom);
  Canvas.MoveTo(R.Left, R.Top);
  Canvas.LineTo(R.Right, R.Top);
  Canvas.MoveTo(R.Right, R.Top);
  Canvas.LineTo(R.Right, R.Bottom);
  Canvas.MoveTo(R.Left, R.Bottom);
  Canvas.LineTo(R.Right, R.Bottom);
end;    end.
-- 向 KTop 的弟兄們致敬!
aresu
一般會員


發表:14
回覆:14
積分:5
註冊:2004-07-13

發送簡訊給我
#12 引用回覆 回覆 發表時間:2004-07-29 09:22:33 IP:220.130.xxx.xxx 未訂閱
成功了~~萬歲~~< > 感謝版大不辭辛勞一篇一篇回~~愛死你了~~< >
系統時間:2024-06-27 0:05:28
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!