¿y ahora cómo queda amigo Román siguiendo tus consejos?:
Código Delphi
[-]unit DBGrilla1;
interface
uses
SysUtils, Classes, Controls, Grids, DBGrids, Messages, SHELLAPI, windows;
type
TDBGrilla = class(TDBGrid)
private
FValorVertical: Boolean;
FValorHorizontal: Boolean;
FScrollAutomatico: Boolean;
procedure WMNCCalcSize(var msg: TMessage); message WM_NCCALCSIZE;
protected
procedure setAutomaticScroll(Value: Boolean);
procedure setVerticalScrollBar(Value: Boolean);
procedure setHorizontalScrollBar(Value: Boolean);
public
published
property VerticalScrollBar: Boolean read FValorVertical write setVerticalScrollBar;
property HorizontalScrollBar: Boolean read FValorHorizontal write setHorizontalScrollBar;
property AutomaticScroll: Boolean read FScrollAutomatico write setAutomaticScroll;
end;
procedure Register;
implementation
procedure TDBGrilla.setAutomaticScroll(Value: Boolean);
begin
if Value <> FScrollAutomatico then
begin
FScrollAutomatico := Value;
end;
end;
procedure TDBGrilla.setVerticalScrollBar(Value: Boolean);
begin
if Value <> FValorVertical then
begin
FValorVertical := Value;
end;
end;
procedure TDBGrilla.setHorizontalScrollBar(Value: Boolean);
begin
if Value <> FValorHorizontal then
begin
FValorHorizontal := Value;
end;
end;
procedure TDBGrilla.WMNCCalcSize(var msg: TMessage);
var
style: Integer;
begin
if VerticalScrollBar then
begin
style := getWindowLong( handle, GWL_STYLE );
if (style and WS_HSCROLL) <> 0 then
SetWindowLong( handle, GWL_STYLE, style and not WS_HSCROLL );
if (style and WS_VSCROLL) <> 0 then
SetWindowLong( handle, GWL_STYLE, style and not WS_VSCROLL );
end;
if HorizontalScrollBar then
begin
style := getWindowLong( handle, GWL_STYLE );
if (style and WS_VSCROLL) <> 0 then
SetWindowLong( handle, GWL_STYLE, style and not WS_VSCROLL );
if (style and WS_HSCROLL) <> 0 then
SetWindowLong( handle, GWL_STYLE, style and not WS_HSCROLL );
end;
if AutomaticScroll then
begin
if Assigned(DataSource) and Assigned(DataSource.DataSet) then
begin
Style := GetWindowLong(Handle, GWL_STYLE);
if DataSource.DataSet.RecordCount > VisibleRowCount then
Style := Style or WS_VSCROLL
else
Style := Style and not WS_VSCROLL;
SetWindowLong(Handle, GWL_STYLE, Style);
end;
end;
inherited;
end;
procedure Register;
begin
RegisterComponents('Data Controls', [TDBGrilla]);
end;
end.
Saludos.