Combobox - StringGrid : supprimer la couleur de focalisation
Pour un ComboBox :
propriété style : csOwnerDrawFixed
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
// Supprimer couleur focus
ComboBox1.Canvas.Brush.Color:= ComboBox1.Color;
ComboBox1.Canvas.FrameRect( Rect );
// On affiche le texte
ComboBox1.Canvas.Font.Color:= ComboBox1.Font.Color;
ComboBox1.Canvas.Textout( Rect.Left + 1 , Rect.Top + 1, ComboBox1.Items[ Index ] );
end;
Pour un StringGrid
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
const
nullRect: TGridRect = ( Left: - 1; Top: - 1; Right: - 1; Bottom: - 1 );
var
couleur: TColor;
begin
if ( gdSelected in State ) or ( gdFocused in State ) then begin
// Couleur cellule
couleur:= StringGrid1.Color;
// Couleur cellule fixe
if ( ACol = 0 ) or ( ARow = 0 ) then
couleur:= StringGrid1.FixedColor;
// Couleur d'effacement
StringGrid1.Canvas.Brush.Color:= couleur;
// Supprimer la bordure de sélection
if ( gdFocused in State ) then
StringGrid1.Selection:= nullRect;
// Restaurer la couleur de police et réaffichage valeur cellule
StringGrid1.Canvas.Font.Color:= StringGrid1.Font.Color;
StringGrid1.Canvas.TextRect( Rect , Rect.Left + 2 , Rect.Top + 2 ,
StringGrid1.Cells[ ACol , ARow ] );
end;
end;