2012-03-29 5 views
3
私はスプリッタコントロールのグラブバーを描画するために、このリンク TSplitter enhanced with grab barに投稿されたコードを使用してい

カスタムペイント方法はのVCLスタイルの色を使用しない

procedure TSplitter.Paint; 
var 
    R: TRect; 
    X, Y: integer; 
    DX, DY: integer; 
    i: integer; 
    Brush: TBitmap; 
begin 
    R := ClientRect; 
    Canvas.Brush.Color := Color; 
    Canvas.FillRect(ClientRect); 

    X := (R.Left+R.Right) div 2; 
    Y := (R.Top+R.Bottom) div 2; 
    if (Align in [alLeft, alRight]) then 
    begin 
    DX := 0; 
    DY := 3; 
    end else 
    begin 
    DX := 3; 
    DY := 0; 
    end; 
    dec(X, DX*2); 
    dec(Y, DY*2); 

    Brush := TBitmap.Create; 
    try 
    Brush.SetSize(2, 2); 
    Brush.Canvas.Brush.Color := clBtnHighlight; 
    Brush.Canvas.FillRect(Rect(0,0,1,1)); 
    Brush.Canvas.Pixels[0, 0] := clBtnShadow; 
    for i := 0 to 4 do 
    begin 
     Canvas.Draw(X, Y, Brush); 
     inc(X, DX); 
     inc(Y, DY); 
    end; 
    finally 
    Brush.Free; 
    end; 

end; 

コードがうまく動作しますが、とき私はvclスタイルを有効にしました。スプリッターを描画するのに使われる色とグラブバーは、vclスタイルで使用されているものに合っていません。私は現在のテーマののVCLスタイルの色を使用してTSplitterを描くことができますどのように

enter image description here

答えて

4

コード(clBtnFace、clBtnHighlight、clBtnShadow)を使用するsystem color constantsは、vclスタイルの色を保存しないため、StyleServices.GetSystemColor関数を使用してこれらをvclスタイルの色に変換する必要があります。

procedure TSplitter.Paint; 
var 
    R: TRect; 
    X, Y: integer; 
    DX, DY: integer; 
    i: integer; 
    Brush: TBitmap; 
begin 
    R := ClientRect; 
    if TStyleManager.IsCustomStyleActive then 
    Canvas.Brush.Color := StyleServices.GetSystemColor(clBtnFace) 
    else 
    Canvas.Brush.Color := Color; 

    Canvas.FillRect(ClientRect); 

    X := (R.Left+R.Right) div 2; 
    Y := (R.Top+R.Bottom) div 2; 
    if (Align in [alLeft, alRight]) then 
    begin 
    DX := 0; 
    DY := 3; 
    end else 
    begin 
    DX := 3; 
    DY := 0; 
    end; 
    dec(X, DX*2); 
    dec(Y, DY*2); 

    Brush := TBitmap.Create; 
    try 
    Brush.SetSize(2, 2); 

    if TStyleManager.IsCustomStyleActive then 
     Brush.Canvas.Brush.Color := StyleServices.GetSystemColor(clBtnHighlight) 
    else 
     Brush.Canvas.Brush.Color := clBtnHighlight; 

    Brush.Canvas.FillRect(Rect(0, 0, Brush.Height, Brush.Width)); 

    if TStyleManager.IsCustomStyleActive then 
     Brush.Canvas.Pixels[0, 0] := StyleServices.GetSystemColor(clBtnShadow) 
    else 
     Brush.Canvas.Pixels[0, 0] := clBtnShadow; 

    for i := 0 to 4 do 
    begin 
     Canvas.Draw(X, Y, Brush); 
     inc(X, DX); 
     inc(Y, DY); 
    end; 
    finally 
    Brush.Free; 
    end; 

end; 
関連する問題