cxCheckBox不显示焦点矩形虚线框

时间:2022-07-19 20:27:45

在cxCheckBox.pas文件中找到 procedure(存储过程)CalculateCustomCheckBoxViewInfo,将FocusRect属性修改为cxEmptyRect


procedure CalculateCustomCheckBoxViewInfo(AViewData: TcxCustomCheckBoxViewData;
AViewInfo: TcxCustomCheckBoxViewInfo);

procedure CheckFocusRectBounds;
var
AMaxRect: TRect;
begin
with AViewInfo do
begin
if Alignment = taCenter then
AMaxRect := Rect(FocusRect.Left, ClientRect.Top, FocusRect.Right, ClientRect.Bottom)
else
begin
AMaxRect := Rect(TextRect.Left - 1, TextRect.Top - 1 + 2 * Integer(IsInplace),
TextRect.Right + 1, TextRect.Bottom + 1 - 2 * Integer(IsInplace));
if AMaxRect.Right > BorderRect.Right - 1 then
AMaxRect.Right := BorderRect.Right - 1;
end;

if FocusRect.Left < AMaxRect.Left then
FocusRect.Left := AMaxRect.Left;
if FocusRect.Top < AMaxRect.Top then
FocusRect.Top := AMaxRect.Top;
if FocusRect.Right > AMaxRect.Right then
FocusRect.Right := AMaxRect.Right;
if FocusRect.Bottom > AMaxRect.Bottom then
FocusRect.Bottom := AMaxRect.Bottom;
end;
end;

begin
with AViewInfo do
begin
BackgroundColor := AViewData.Style.Color;

if
(Focused and ((not IsInplace or AViewData.Properties.IsEmbeddedEdit) and (Alignment <> taCenter) or
IsInplace and (Alignment = taCenter) and (epoShowFocusRectWhenInplace in PaintOptions))) then
begin
if Alignment = taCenter then
begin
// FocusRect := ClientRect; 原版FocusRect属性
FocusRect := cxEmptyRect;//将FocusRect属性修改为cxEmptyRect
InflateRect(FocusRect, -1, -1);
end
else if Length(Text) <> 0 then
begin
// FocusRect := TextRect; 原版FocusRect属性
FocusRect := cxEmptyRect; //将FocusRect属性修改为cxEmptyRect
// if not AViewData.Properties.FullFocusRect then 如果不注释此if代码,需要手动对checkbox的FullFocusRect属性设置为True
// begin
// cxScreenCanvas.Font := Font;
// cxScreenCanvas.TextExtent(Text, FocusRect, DrawTextFlags);
// cxScreenCanvas.Dormant;
// end;
InflateRect(FocusRect, 1, 1);
Inc(FocusRect.Bottom);
end
else
FocusRect := cxEmptyRect;
end
else
FocusRect := cxEmptyRect;
if not IsRectEmpty(FocusRect) then
CheckFocusRectBounds;
end;
end;