線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2104
推到 Plurk!
推到 Facebook!

以程式碼控制StringGrid 內 Cell 的反白

答題得分者是:jest0024
bruce0211
版主


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

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-08 14:54:58 IP:211.21.xxx.xxx 未訂閱
TEdit 有 SelStart & SelLength 可控制編輯文字的反白 而 StringGrid 沒有這兩個屬性,那該如何控制 一進 cell , 就讓該 cell 內所有文字反白呢 ? (不是整個 cell 框框反白) p.s. 我知 StringGrid1.EditerMode:=false 就讓該個框框反白 發表人 - bruce0211 於 2004/04/08 14:57:04
jest0024
高階會員


發表:11
回覆:310
積分:224
註冊:2002-11-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-08 15:25:27 IP:203.67.xxx.xxx 未訂閱
引言: TEdit 有 SelStart & SelLength 可控制編輯文字的反白 而 StringGrid 沒有這兩個屬性,那該如何控制 一進 cell , 就讓該 cell 內所有文字反白呢 ? (不是整個 cell 框框反白) p.s. 我知 StringGrid1.EditerMode:=false 就讓該個框框反白 發表人 - bruce0211 於 2004/04/08 14:57:04
StringGrid編緝時會建立一個TInplaceEdit物件,繼承自TCustomEdit,只要能 抓住這個元件就能使用該元件的方法..
procedure Button..
var
  i:Integer;
  e:TEdit;
begin
  e:=nil;
  with StringGrid1 do begin
    SetFocus; //焦點移到StringGrid1
    EditorMode:=True; //將TInplaceEdit給顯示或建立出來
    for i:=0 to ComponentCount-1 do
      if Components[i].ClassName='TInplaceEdit' then 
         e:=TEdit(Components[i]); //找出StringGrid的TInplaceEdit元件
    if e<>nil then begin
      e.SelStart :=1; //能使用TEdit的屬性了!!
      e.SelLength:=3;
    end;
  end;
end;
想買台TPC..TTAB-B12D
bruce0211
版主


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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-08 15:33:38 IP:211.21.xxx.xxx 未訂閱
真的可以耶~ 但是..沒有...簡單一點的方法 ??
jest0024
高階會員


發表:11
回覆:310
積分:224
註冊:2002-11-24

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-04-08 17:35:51 IP:203.67.xxx.xxx 未訂閱
引言: 真的可以耶~ 但是..沒有...簡單一點的方法 ??
剛看了一下TStringGrid源碼,發現他將Edit開放屬性為InplaceEditor 想買台TPC..TTAB-B12D
bruce0211
版主


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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-04-08 22:01:14 IP:211.21.xxx.xxx 未訂閱
引言: 剛看了一下TStringGrid源碼,發現他將Edit開放屬性為InplaceEditor
可是..StringGrid 不能直接拿 InplaceEditor 屬性來用吧 .... 我把之前長官提供的方法包成一個函式
// ================================================================
// 函數名稱:_StrGridEditorMode
// 中文說明:進入 EditorMode , 並將全部字元反白
// 傳 回 值:
// 參    數:
// 機能說明:取代 StringGrid.EditorMode:=true;  並將全部字元反白
// 使用範例:_StrGridEditorMode(StringGrid1);
// ================================================================
procedure _StrGridEditorMode(MyStringGrid:TStringGrid);
var
  i:Integer;
  e:TEdit;
begin
  MyStringGrid.EditorMode:=True;      for i:=0 to MyStringGrid.ComponentCount-1 do
      if MyStringGrid.Components[i].ClassName='TInplaceEdit' then
         e:=TEdit(MyStringGrid.Components[i]); //找出StringGrid的TInplaceEdit元件      if e<>nil then
  begin
    e.SelStart :=0; //能使用TEdit的屬性了!!
    e.SelLength:=Length(e.text);
  end;    end;
 
jest0024
高階會員


發表:11
回覆:310
積分:224
註冊:2002-11-24

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-04-09 02:14:22 IP:211.74.xxx.xxx 未訂閱
可以自行開放InplaceEditor屬性!!
Type
  TStringGrid = class(Grids.TStringGrid)
  public
    property InplaceEditor;
  end;
  TForm = class(.......
醬樣就能使用InplaceEditor這個屬性了!! 想買台TPC..TTAB-B12D
bruce0211
版主


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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-04-09 16:50:05 IP:211.21.xxx.xxx 未訂閱
原來這樣就可以用了 < class="code">unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls, Buttons; type TStringGrid = class(Grids.TStringGrid) public property InplaceEditor; end; TForm1 = class(TForm) StringGrid1: TStringGrid; BitBtn1: TBitBtn; procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm}
系統時間:2024-06-25 14:37:33
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!