2009-07-27 17 views

答えて

2

解決策は、コントロールの継承によって異なります。 Paintメソッドのオーバーライドが必要なものと、ownerdrawが必要なものがあります。私は一般的な解決策を知らない。

一部の場合、ShowFocusRectプロパティはfalseに設定できます。これは、適切なコンポーネントの利点の1つです。

フォーカス矩形が標準的なWindowsユーザーインターフェイスの一部であると主張する人もいます。関連する議論はhereです。私はいくつかの状況で動作を無効にする場合があると確信しています。

0

これは、this newsgroup postからownerdrawを使用してStringGridのフォーカス矩形を抑制する例です。これは、Paintメソッドでフォーカス矩形が描画されるコントロールでは機能しません。 falseに描画

既定値に設定、OnDrawCellイベントにこれを添付:

procedure TMiscForm.StringGrid1DrawCell(Sender: TObject; 
      ACol, ARow: Integer; 
      Rect : TRect; 
      State : TGridDrawState); 
var 
    SG: TStringGrid; 
begin 
    if Sender is TStringGrid then 
    begin 
    SG:= TStringGrid(Sender); 
    SG.Canvas.Font:= SG.Font; 
    SG.Canvas.Brush.Color:= SG.Color; 
    SG.Canvas.Brush.Style:= bsSolid; 

    if gdFixed in State then 
     SG.Canvas.Brush.Color:= SG.FixedColor; 

    if (gdSelected in State) and not (gdFocused in State) then 
    begin 
     SG.Canvas.Brush.Color:= clHighLight; 
     SG.Canvas.Font.color := clHighLightText; 
    end; 

    SG.Canvas.Pen.Color := SG.Canvas.Brush.Color; 
    SG.Canvas.Pen.Mode := pmCopy; 
    SG.Canvas.Pen.Style := psSolid; 
    SG.Canvas.Pen.Width := 1; 
    SG.Canvas.Rectangle(Rect); 

    if SG.Canvas.Ctl3D and (gdFixed in State) then 
    begin 
     if goFixedVertLine in SG.Options then 
     begin 
     SG.Canvas.Pen.Color := clBtnHighLight; 
     MoveTo(Rect.Left, Rect.Bottom-1); 
     LineTo(Rect.Left, Rect.Top); 
     SG.Canvas.Pen.Color := clBtnShadow; 
     MoveTo(Rect.Right-1, Rect.Top); 
     if goFixedHorzLine in SG.Options then 
      LineTo(Rect.Right-1, Rect.Bottom) 
     else LineTo(Rect.Right-1, Rect.Bottom+SG.GridLineWidth); 
     end; 

     if goFixedHorzLine in SG.Options then 
     begin 
     SG.Canvas.Pen.Color := clBtnHighLight; 
     MoveTo(Rect.Left, Rect.Top); 
     LineTo(Rect.Right, Rect.Top); 
     SG.Canvas.Pen.Color := clBtnShadow; 
     if goFixedVertLine in SG.Options then 
     begin 
      MoveTo(Rect.Left+1, Rect.Bottom-1); 
      LineTo(Rect.Right, Rect.Bottom-1) 
     end 
     else 
     begin 
      MoveTo(Rect.Left, Rect.Bottom-1); 
      LineTo(Rect.Right + SG.GridLineWidth, Rect.Bottom-1); 
     end; 
     end; 
    end; 

    SG.Canvas.Brush.Style:= bsClear; 
    TextRect(Rect, Rect.Left + 2, Rect.Top + 2, SG.Cells[ACol,ARow]); 

    SG.Canvas.Brush.Style:= bsSolid; 
    if gdFocused in State then 
     SG.Canvas.DrawFocusRect(Rect); 
    end; 
end; 
0

私はこれが古い質問です知っているが、あなたはまだ興味があれば、いつでもコントロール

procedure TfrmPic.MyStringGridDrawCell(Sender: TObject; 
    ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); 
begin 
    // Deliberately draw focus rectangle which is subsequently redrawn; 
    if gdSelected in State then 
    MyStringGrid.Canvas.DrawFocusRect(Rect); 
end; { procedure TfrmPic.sgCorDrawCell } 
+0

これは一般的には機能しますか? OPは問題のオブジェクトの継承を指定しませんでした。 – Argalatyr

関連する問題