2009-07-27 7 views

Répondre

2

La solution pour cela varie en fonction de l'héritage du contrôle. Certains nécessitent un remplacement de la méthode Paint, d'autres nécessitent une reprise propriétaire. Je ne connais pas de solution générale.

Pour certaines Raize components, il existe une propriété ShowFocusRect que vous pouvez définir sur false - un des avantages des composants bien faits. Certains diront que ce que vous proposez n'est pas une bonne idée - arguant que le rectangle de focus fait partie de l'interface utilisateur Windows standard (vous trouverez une discussion pertinente here). Je suis sûr qu'il y a un cas à faire pour contourner le comportement dans certaines situations.

0

Ceci est un exemple de suppression du rectangle de focus dans un StringGrid à l'aide de ownerdraw, à partir de this newsgroup post. Cela ne fonctionnera pas pour les contrôles pour lesquels le rectangle de focus est dessiné dans la méthode Paint.

Set de dessin par défaut sur false, le joindre à l'événement 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

Je sais que c'est une vieille question, mais si votre vous pouvez toujours intéressé toujours essayer

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

Cela fonctionnera-t-il généralement? L'OP n'a pas spécifié l'héritage de l'objet en question. – Argalatyr

Questions connexes