【StringGrid的问题】 |
尚未結案
|
iamnick
一般會員 ![]() ![]() 發表:5 回覆:15 積分:4 註冊:2005-05-26 發送簡訊給我 |
|
wameng
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
|
iamnick
一般會員 ![]() ![]() 發表:5 回覆:15 積分:4 註冊:2005-05-26 發送簡訊給我 |
|
iamnick
一般會員 ![]() ![]() 發表:5 回覆:15 積分:4 註冊:2005-05-26 發送簡訊給我 |
|
wameng
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
|
iamnick
一般會員 ![]() ![]() 發表:5 回覆:15 積分:4 註冊:2005-05-26 發送簡訊給我 |
|
iamnick
一般會員 ![]() ![]() 發表:5 回覆:15 積分:4 註冊:2005-05-26 發送簡訊給我 |
|
wameng
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
我臨時寫一下。 只判斷 Ctrl 複選。
參考一下。
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids; type TForm1 = class(TForm) StringGrid1: TStringGrid; procedure FormCreate(Sender: TObject); procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); private SelectedRows : Array of Boolean; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); begin SetLength(SelectedRows,StringGrid1.RowCount); end; procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var I :integer; ARect:TRect; OldSelected:Boolean; begin if (ssCtrl in Shift) and (Button=mbLeft) then begin SelectedRows[StringGrid1.Row] := True; end else for I:=0 to StringGrid1.RowCount-1 do begin OldSelected := SelectedRows[I]; SelectedRows[I] := I = StringGrid1.Row; if SelectedRows[I]<> OldSelected then begin ARect := StringGrid1.CellRect(0,I); With ARect do ARect := Rect(0,Top,StringGrid1.Width,Bottom); Windows.InvalidateRect(StringGrid1.Handle,@ARect,True); end; end; end; procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if (ACol>0) and (ARow>0) and SelectedRows[ARow] then With StringGrid1 do begin Canvas.Brush.Color := ClHighLight; Canvas.Font.Color := ClHighLightText; Canvas.TextRect(Rect, Rect.Left 2, Rect.Top 2, Cells[ACol, ARow]); end; end;~~~~~~~~~~~ 難得聰明,常常糊塗。 ~~~~~~~~~~~ |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |