全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2219
推到 Plurk!
推到 Facebook!

關閉 StringGrid 的 Focus

尚未結案
bruce0211
版主


發表:157
回覆:668
積分:279
註冊:2002-06-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-02 11:44:04 IP:211.21.xxx.xxx 未訂閱
請問有沒長官做過 將 StringGrid 的 Focus 關閉 也就是完全看不出 cell 的 focus 框框(cell 四邊方型的虛線) 就像是 StringGrid 被 disabled 一樣 但 StringGrid 仍可做 cell內容編輯 捲軸仍可使用
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-02 11:49:15 IP:202.39.xxx.xxx 未訂閱
var
  myRect: TGridRect;
begin
  myRect.Left := -1;
  myRect.Top := -1;
  myRect.Right := -1;
  myRect.Bottom := -1;
  StringGrid1.Selection := myRect;
end;
-- He just never quits.
bruce0211
版主


發表:157
回覆:668
積分:279
註冊:2002-06-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-02 13:08:36 IP:211.21.xxx.xxx 未訂閱
引言:
var
  myRect: TGridRect;
begin
  myRect.Left := -1;
  myRect.Top := -1;
  myRect.Right := -1;
  myRect.Bottom := -1;
  StringGrid1.Selection := myRect;
end;
-- He just never quits.
感謝 hagar 長官 不過我剛試了有一缺點 我將程式碼放在
 
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  myRect: TGridRect;
begin
  myRect.Left := -1;
  myRect.Top := -1;
  myRect.Right := -1;
  myRect.Bottom := -1;
  StringGrid1.Selection := myRect;
end;
會成我將滑鼠移到任一 cell , 編輯時還是在左上角第一個 cell 我是希望不要看到 focus 即可 其他的動作跟 focus 未隱藏前一樣 不過我已用其他方法測出來了 整理如下
 
//---------------------------------------------------------------------------
procedure TForm1.FormCreate(Sender: TObject);
begin
  StringGrid1.DefaultDrawing:=false;
end;
//---------------------------------------------------------------------------
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var FixRect: TRect;
begin      //Default 值
  TStringGrid(Sender).Canvas.Brush.Color := clWhite;
  TStringGrid(Sender).Canvas.Font.Color := clBlack;
  TStringGrid(Sender).Canvas.Font.Size := 12;
  TStringGrid(Sender).Canvas.Font.Name := '細明體';      //判斷是否是 Fixed 行列
  if (gdFixed in State) then
     begin
       TStringGrid(Sender).Canvas.Brush.Color := clBtnFace;
       Frame3D( TStringGrid(Sender).Canvas, Rect, clBtnHighlight, clBtnShadow, 1 );
     end;      {
  //若要自行繪製藍色的 Focus 時
  if (gdSelected in State) then
     begin
       TStringGrid(Sender).Canvas.Brush.Color := clBlue;
       TStringGrid(Sender).Canvas.Font.Color := clWhite;
     end;
  }
 
  //填滿每一 Cell 背景 (清掉舊 Cell Text)
  TStringGrid(Sender).Canvas.FillRect(Rect);      //繪製新的 Cell Text
  TStringGrid(Sender).Canvas.TextRect (Rect, Rect.Left, Rect.Top, TStringGrid(Sender).Cells[ACol,ARow]);    end;    
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-04-03 15:01:52 IP:218.32.xxx.xxx 未訂閱
試試看:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if gdFocused in State then DrawFocusRect(StringGrid1.Canvas.Handle,Rect); //再畫一次虛線框, 就是復原成無虛線框
end;
bruce0211
版主


發表:157
回覆:668
積分:279
註冊:2002-06-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-04-03 18:01:40 IP:211.21.xxx.xxx 未訂閱
引言: 試試看:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if gdFocused in State then DrawFocusRect(StringGrid1.Canvas.Handle,Rect); //再畫一次虛線框, 就是復原成無虛線框
end;
挖 ! 太誇張了... 真的可以用耶 ~ 我試了那麼多行, Mickey長官一行就解決
bruce0211
版主


發表:157
回覆:668
積分:279
註冊:2002-06-13

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-04-03 19:25:28 IP:211.21.xxx.xxx 未訂閱
剛又發現一個問題 Mickey 長官提供的方法雖好用 但當該 StringGrid 的 Focus 跑到別的元件時 該 StringGrid 本身的 Cell Focus 又看得到了 用我的方法則不會
系統時間:2024-06-01 23:36:09
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!