StringGrid Rows如何選取捲動(沒按ScrollBar)? |
尚未結案
|
way888
初階會員 發表:32 回覆:76 積分:36 註冊:2005-05-31 發送簡訊給我 |
|
st33chen
尊榮會員 發表:15 回覆:591 積分:1201 註冊:2005-09-30 發送簡訊給我 |
您好, 請問您設了那些 stringgrid 的 property.
我試過, 在一個新的 project 拉一個 tstringgrid, rowcount 設為40;
再拉二個 tedit; stringgrid 的 mousedown, mouseup 的 handler 分別如下: procedure TForm1.StringGrid1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
edit1.Text:=inttostr(stringgrid1.Selection.top);
end; procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
edit2.Text:=inttostr(stringgrid1.Selection.Bottom);
end; 可以做到您的需求, 且會自動 scroll, 唯一缺點是 selection 的top 那一 cell 不會變成藍色, 而是以虛線框起來... 不知我是否理解您的問題
------
IS IT WHAT IT IS 我是 李慕白 請倒著唸. 又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦); 都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲. |
way888
初階會員 發表:32 回覆:76 積分:36 註冊:2005-05-31 發送簡訊給我 |
st33chen您好:
非常感謝你的回應,stringgrid 的 property.option.goedit是設true,
所以無法使用stringgrid本身的窗選功能。
為回應你的熱心參與,我把主要code貼上來,大家互相研究研究,其實我已經想到了另一個辦法了,就是用Shift鍵代替MouseMove,只不過無法馬上變色而已。
順便請教你一下,你知道Shift鍵的代碼嗎?
我的這個stringgrid的功能是要做到,複製、剪下、貼上、插入、刪除...等功能,現在已經測試差不多了。
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if (ARow>=a) and (ARow<=b) and (ACol>=c)and (ACol<=d) then begin StringGrid1.Canvas.Brush.Color:=clRed; StringGrid1.Canvas.FillRect(Rect); StringGrid1.Canvas.TextOut(Rect.Left 2,Rect.Top 2,StringGrid1.Cells[Acol,ARow]); end; end; procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin id := Stringgrid1.Mousecoord(x,y); //取得目前mouse所在之col及row if (id.x >= 0) and (id.y > 0) then //從col0及row1開始 Edit1.Text := '(' IntToStr(id.x) ',' IntToStr(id.Y) ')'; if e = 1 then begin b:=id.Y; stringGrid1.Repaint; end; end; procedure TForm1.FormCreate(Sender: TObject); begin a:=-1; b:=-1; c:=-1; d:=-1; e:=-1; end; procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if (id.X = 0)and(id.Y >0) then //限制只能col第一行變顏色 begin a:=id.Y; c:=id.X; e:=1; end; edit2.Text:=inttostr(a); end; procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin e:=0; if (id.X = 0)and(id.Y >0) then begin b:=id.Y; d:=id.X; end; edit3.Text:=inttostr(b); stringGrid1.Repaint; end; |
Mickey
版主 發表:77 回覆:1882 積分:1390 註冊:2002-12-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |