给cxGrid 鼠标所在行加个大框框

声明:本类来自cxGrid中的一个demo

View Code
unit RecStyle;

interface

uses
Controls, Classes, Messages, Types;

type
TMycxDraw = class(TWinControl)
private
FAPoint: Tpoint;
procedure SetAPoint(const Value: Tpoint);
protected
procedure AdjustFrameRgn;
procedure Resize; override;
public
constructor Create(AOwner: TComponent); override;
published
property APoint: Tpoint read FAPoint write SetAPoint;
end;

implementation

uses
Windows, Graphics;

procedure TMycxDraw.AdjustFrameRgn;
const
AElipsWidth = 4;
var
ARgn1, ARgn2: HRGN;
ARect: TRect;
begin
if Parent <> nil then
begin
ARect := Rect(0, 0, Width, Height);
ARgn1 := CreateRoundRectRgn(ARect.Left, ARect.Top, ARect.Right,
ARect.Bottom, AElipsWidth, AElipsWidth);
InflateRect(ARect, -2, -2);
ARgn2 := CreateRoundRectRgn(ARect.Left, ARect.Top, ARect.Right,
ARect.Bottom, AElipsWidth, AElipsWidth);
CombineRgn(ARgn1, ARgn2, ARgn1, RGN_XOR);
SetWindowRgn(Handle, ARgn1, True);
DeleteObject(ARgn1);
DeleteObject(ARgn2);
end;
end;

constructor TMycxDraw.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Color := clRed;
end;

procedure TMycxDraw.Resize;
begin
AdjustFrameRgn;
inherited;
end;

procedure TMycxDraw.SetAPoint(const Value: Tpoint);
begin
FAPoint := Value;
end;

end.

实例化:

AFrameControl := TMycxDraw.Create(Self);
AFrameControl.Parent := Self;
AFrameControl.Visible := False;

cxGrid中设置 :

procedure TMainForm.cxMyDBCardMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
Var
AHitTest: TcxCustomGridHitTest;
ATrackItem: TcxCustomGridTableItem;
ATrackRec: TcxCustomGridRecord;
begin
AHitTest := (Sender as Tcxgridsite).GridView.ViewInfo.GetHitTest(X, Y);
if AHitTest is TcxGridRecordCellHitTest then
begin
ATrackItem := TcxGridRecordCellHitTest(AHitTest).Item;
ATrackRec := TcxGridRecordCellHitTest(AHitTest).GridRecord;
//设置位置
AFrameControl.Left := ATrackRec.ViewInfo.RealBounds.Left + cxSplitter1.Left
+ cxSplitter1.Width + 3;
AFrameControl.Top := ATrackRec.ViewInfo.RealBounds.Top + cxPageControl1.Top
+ cxHeader6.Height + Panel1.Height + 4;
AFrameControl.Width := ATrackRec.ViewInfo.Width;
AFrameControl.Height := ATrackRec.ViewInfo.Height;
AFrameControl.Visible := True;
end;
end;

效果:





原文地址:https://www.cnblogs.com/xspace/p/2248672.html