type TEditLight= class (TEdit) private FEditSel: Boolean; procedure WMNCPAINT(var msg: TMessage); message WM_NCPaint; procedure SetEditSel(Value: Boolean); published property EditSel: Boolean read FEditSel write SetEditSel default False; end; procedure TEditLight.SetEditSel(Value: Boolean); begin if self.FEditSel <> Value then begin self.FEditSel := Value; Self.Invalidate; end; end; procedure TEditLight.WMNCPAINT(var msg: TMessage); var DC: HDC; BorderBrush: HBRUSH; R: TRect; begin DC := GetWindowDC(Handle); try SetRect(R, 0, 0, Width, Height); if FEditSel then begin BorderBrush := CreateSolidBrush(RGB(123, 228, 255)); FrameRect(DC, R, BorderBrush); //绘制外部高亮边框 DeleteObject(BorderBrush); InflateRect(R, -1, -1); end else begin InflateRect(R, -1, -1); BorderBrush := CreateSolidBrush(ColorToRGB(Color)); FrameRect(DC, R, BorderBrush); //未得焦点时,用本身的颜色填充内部线框 DeleteObject(BorderBrush); InflateRect(R, 1, 1); end; BorderBrush := CreateSolidBrush(RGB(78, 160, 209)); FrameRect(DC, R, BorderBrush); //绘制默认的边线框 DeleteObject(BorderBrush); finally ReleaseDC(Handle, DC); end; end;