請問如何改變GroupBox 中邊框的顏色呢? |
尚未結案
|
clericc
一般會員 發表:4 回覆:1 積分:1 註冊:2007-05-07 發送簡訊給我 |
|
Victor4022
中階會員 發表:0 回覆:76 積分:90 註冊:2011-02-20 發送簡訊給我 |
小弟參考了 TGroupBox 所引用的 StdCtrls.pas 內容, 繼承 TGroupBox 之後, 改寫一行即可達到您想要的功能:
[code delphi] type TColorGroupBox = class(TGroupBox) protected procedure Paint; override; end; implementation { TColorGroupBox } procedure TColorGroupBox.Paint; var H: Integer; R: TRect; Flags: Longint; CaptionRect, OuterRect: TRect; Size: TSize; Box: TThemedButton; // uses Themes.pas Details: TThemedElementDetails; begin with Canvas do begin Font := Self.Font; if ThemeServices.ThemesEnabled then begin if Text <> '' then begin GetTextExtentPoint32(Handle, PChar(Text), Length(Text), Size); CaptionRect := Rect(0, 0, Size.cx, Size.cy); if not UseRightToLeftAlignment then OffsetRect(CaptionRect, 8, 0) else OffsetRect(CaptionRect, Width - 8 - CaptionRect.Right, 0); end else CaptionRect := Rect(0, 0, 0, 0); OuterRect := ClientRect; OuterRect.Top := (CaptionRect.Bottom - CaptionRect.Top) div 2; with CaptionRect do ExcludeClipRect(Handle, Left, Top, Right, Bottom); if Enabled then Box := tbGroupBoxNormal else Box := tbGroupBoxDisabled; Details := ThemeServices.GetElementDetails(Box); ThemeServices.DrawElement(Handle, Details, OuterRect); SelectClipRgn(Handle, 0); if Text <> '' then ThemeServices.DrawText(Handle, Details, Text, CaptionRect, DT_LEFT, 0); end else begin H := TextHeight('0'); R := Rect(0, H div 2 - 1, Width, Height); if Ctl3D then begin Inc(R.Left); Inc(R.Top); // Brush.Color := clBtnHighlight; Brush.Color := clBlue; // 改寫此行 FrameRect(R); OffsetRect(R, -1, -1); Brush.Color := clBtnShadow; end else Brush.Color := clWindowFrame; FrameRect(R); if Text <> '' then begin if not UseRightToLeftAlignment then R := Rect(8, 0, 0, H) else R := Rect(R.Right - Canvas.TextWidth(Text) - 8, 0, 0, H); Flags := DrawTextBiDiModeFlags(DT_SINGLELINE); DrawText(Handle, PChar(Text), Length(Text), R, Flags or DT_CALCRECT); Brush.Color := Color; DrawText(Handle, PChar(Text), Length(Text), R, Flags); end; end; end; end; [/code] 當然, 您也可以將它封裝得更完美, 將 BorderColor 提升至 published property, 再包裝成 Component |
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |