2013-10-23 19 views
0

我想有一個網格,所有行看起來都一樣 在Delphi中,如何讓用戶調整TStringGrid列的大小而不固定行?通常情況下,您只能調整固定行,並且不能使整個網格固定。Delphi可以讓用戶調整TStringGrid列的大小而不固定行嗎?

我正在使用XE2。

TIA

馬克

+0

列,行......請您詳細說明究竟應該做什麼和不應該爲用戶做些什麼?也許一些PNG截圖突出了chanegs箭頭?我無法理解一點... –

+0

http://docwiki.embarcadero.com/Libraries/XE5/en/Vcl.Grids.TDrawGrid.Options 這表明任何列和行都可以調整大小,您是否設置了正確? –

+0

這裏引用的問題是,Delphi(AFIAK)只會在列標題行(固定行)上設置鼠標的「resize」遊標。 –

回答

1

您可能會覆蓋CalcSizingState。


- 國gsRowSizing如果(如果Alt鍵被按下的MouseMove在本例中檢查以下)的條件得到滿足,並
- 使用MouseToCell指數計算出的指數從的MouseDown。

一些微調可能是必要的。

type 

    TStringGrid = Class(Grids.TStringGrid) 
    private 
    FIsSizing: Boolean; 
    FIndex: Integer; 
    procedure CalcSizingState(X, Y: Integer; var State: TGridState; var Index: Longint; var SizingPos, SizingOfs: Integer; var FixedInfo: TGridDrawInfo); override; 
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; 
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; 
    private 

    End; 

    TForm3 = class(TForm) 
    StringGrid1: TStringGrid; 
    private 
    { Private-Deklarationen } 
    public 
    { Public-Deklarationen } 
    end; 

var 
    Form3: TForm3; 

implementation 

{$R *.dfm} 
{ TStringGrid } 

procedure TStringGrid.CalcSizingState(X, Y: Integer; var State: TGridState; var Index, SizingPos, SizingOfs: Integer; var FixedInfo: TGridDrawInfo); 
begin 
    inherited; 
    if FIsSizing then 
    State := gsRowSizing; 
    if (FIndex > -1) then 
    begin 
    Index := FIndex; 
    end; 
end; 

procedure TStringGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); 
var 
    Col: Integer; 
begin 
    inherited; 
    MouseToCell(X, Y, Col, FIndex); 
end; 

procedure TStringGrid.MouseMove(Shift: TShiftState; X, Y: Integer); 
begin 
    inherited; 
    FIsSizing := ssAlt in Shift; 
end; 
相關問題