如何像BCB的IDE, 按Ctrl+Shift+i 來向右移動文字區域 |
答題得分者是:dllee
|
ys168
初階會員 發表:3 回覆:24 積分:25 註冊:2005-10-14 發送簡訊給我 |
|
dllee
站務副站長 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
提供您一個寫作/測試方向。
1. 先使用 SelStart, SelLength, SelText 等找到選擇的文字區域是第幾 row 到第幾 row 2. row 確定後,就可以直接針對選擇的 row 按需要去除最前面的空白,或增加最前面的空白達到想要的功能。 3. 按鈕設定的部分,可以用 Menu 或 PopupMenu 設兩個 Item 一個作左移一個右移並設好熱鍵即可,使用熱鍵操作。 以上只要完成第 1 項後 2 項應該不是什麼大問題。 ■ Seednet ShareMe 免費網路硬碟, 申請送2G, 用 MSN 幫她打廣告加 10G, 推薦1人加 1G, 活動只到 9 月底, 請把握時機 ■
------
http://www.ViewMove.com |
ys168
初階會員 發表:3 回覆:24 積分:25 註冊:2005-10-14 發送簡訊給我 |
dllee 版大您好! 感謝指導.
我測試了如下程式是可以用, 但所反白的區塊的下一列是空白列, 就 OK ,否則反白的區塊的下一列有資料, 則執行會怪怪地? 也一起移動! dllee 副站長 是否能幫我看一下是bug出在哪地方? //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int _pos; int wx; TPoint pos; int StartPos,EndPos; int TopRow,BottomRow; int na; TStringList *psn; char *Rj(char *rStr,char *buf,int fieldwid); //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::RichEdit1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { StartPos = RichEdit1->SelStart; pos = RichEdit1->CaretPos; TopRow=RichEdit1->CaretPos.y; psn->Clear(); wx=2; na=0; } //--------------------------------------------------------------------------- void __fastcall TForm1::RichEdit1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { BottomRow = RichEdit1->CaretPos.y; EndPos = RichEdit1->SelLength StartPos; for(int i=TopRow;i< BottomRow;i ) psn->Add(RichEdit1->Lines->Strings[i]); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { psn = new TStringList; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClick(TObject *Sender) { delete psn; } //--------------------------------------------------------------------------- char *Rj(char *rStr,char *buf,int fieldwid) { int T,T1,Lr; for(Lr=0;rStr[Lr];Lr ); if(Lr<=fieldwid) { T1=fieldwid-Lr-1; for(T=0;T<=T1;T ) buf[T]=' '; for(T1=0,fieldwid--;T<=fieldwid;T ,T1 ) buf[T]=rStr[T1]; buf[T]=0; } else { buf[fieldwid]=0; for(fieldwid--,Lr--;fieldwid>=0;fieldwid--,Lr--) buf[fieldwid]=rStr[Lr]; } return(buf); } //---------------------------------------------------------------------------- // 按鍵 Ctrl Shift K 右移2個英文字寬 void __fastcall TForm1::RichEdit1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { char buf[256]=""; if ( Shift.Contains(ssCtrl) && Shift.Contains(ssShift)) { if(Key==75) { RichEdit1->ClearSelection(); for(int i=0;i< psn->Count;i ) { int nw=psn->Strings[i].Length(); nw =wx; Rj(psn->Strings[i].c_str() ,buf,nw); RichEdit1->Lines->Insert(pos.y i ,buf); } RichEdit1->SelStart= StartPos wx; RichEdit1->SelLength=EndPos-StartPos wx*(BottomRow-TopRow-1); wx =2; RichEdit1->SetFocus(); } } } //---------------------------------------------------------------------------
------
yangshuh
編輯記錄
ys168 重新編輯於 2007-09-25 11:46:13, 註解 無‧
|
ys168
初階會員 發表:3 回覆:24 積分:25 註冊:2005-10-14 發送簡訊給我 |
[code cpp] 感謝 dllee 的提醒, 我重新再貼上更完整的程式碼如下: Ctrl Shift K 向右移動文字區域 Ctrl Alt K 向左移動文字區域 //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int wx; TPoint pos; int StartPos,EndPos; int TopRow,BottomRow; int na; bool Right_fg,Left_fg; TStringList *psn; char *Rj(char *rStr,char *buf,int fieldwid); //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::RichEdit1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { StartPos = RichEdit1->SelStart; pos = RichEdit1->CaretPos; TopRow=RichEdit1->CaretPos.y; psn->Clear(); wx=0; na=0; } //--------------------------------------------------------------------------- void __fastcall TForm1::RichEdit1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { BottomRow = RichEdit1->CaretPos.y; EndPos = RichEdit1->SelLength StartPos; for(int i=TopRow;i< BottomRow;i ) psn->Add(RichEdit1->Lines->Strings[i]); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { psn = new TStringList; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClick(TObject *Sender) { delete psn; } //--------------------------------------------------------------------------- // 插入空白函數 char *Rj(char *rStr,char *buf,int fieldwid) { int T,T1,Lr; for(Lr=0;rStr[Lr];Lr ); if(Lr<=fieldwid) { T1=fieldwid-Lr-1; for(T=0;T<=T1;T ) buf[T]=' '; for(T1=0,fieldwid--;T<=fieldwid;T ,T1 ) buf[T]=rStr[T1]; buf[T]=0; } else { buf[fieldwid]=0; for(fieldwid--,Lr--;fieldwid>=0;fieldwid--,Lr--) buf[fieldwid]=rStr[Lr]; } return(buf); } //---------------------------------------------------------------------------- // 按鍵 -移動文字區域2個英文字寬 void __fastcall TForm1::RichEdit1KeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { char buf[128]=""; if ( Shift.Contains(ssCtrl) && Shift.Contains(ssShift)) { // 按鍵 Ctrl Shift K 右移2個英文字寬 if(Key==75) { if(Left_fg) { Left_fg=false; Right_fg=true; wx =4; } else wx =2; for(int i=0;i< psn->Count;i ) { RichEdit1->Lines->Delete(pos.y i); // 刪除列 int nw=psn->Strings[i].Length(); nw =wx; Rj(psn->Strings[i].c_str() ,buf,nw); RichEdit1->Lines->Insert(pos.y i ,buf); } RichEdit1->SelStart= StartPos wx; RichEdit1->SelLength=EndPos-StartPos wx*(BottomRow-TopRow-1); RichEdit1->SetFocus(); } } if(Shift.Contains(ssCtrl) && Shift.Contains(ssAlt)) { // 按鍵 Ctrl Alt K 左移2個英文字寬 if(Key==75) { if(Right_fg) { wx-=4; Right_fg=false; Left_fg=true; } else wx-=2; for(int i=0;i< psn->Count;i ) { RichEdit1->Lines->Delete(pos.y i); // 刪除列 int nw=psn->Strings[i].Length(); nw =wx; Rj(psn->Strings[i].c_str() ,buf,nw); RichEdit1->Lines->Insert(pos.y i ,buf); } RichEdit1->SelStart= StartPos wx; RichEdit1->SelLength=EndPos-StartPos wx*(BottomRow-TopRow-1); RichEdit1->SetFocus(); } } } //--------------------------------------------------------------------------- [/code]
------
yangshuh
編輯記錄
ys168 重新編輯於 2007-09-27 19:28:22, 註解 無‧
|
dllee
站務副站長 發表:321 回覆:2519 積分:1711 註冊:2002-04-15 發送簡訊給我 |
感謝分享
您之後的程式有看到,但是看到格式很亂,又沒有時間可以很仔細的看,也就沒幫您除錯了。 建議您在貼程式時,使用編輯視窗上方的 程式碼區塊: Delphi, C , C#, PHP, HTML.... 等, 按下 C 再將 請在此區域輸入程式碼 刪除,貼上您的程式,可保留原縮排的效果,會比較好看一些。 ■ VMASK - ViewMove Automation Software Kernel ■ VMIO-Server/SECS/GEM ■ dllee's blog ■ dllee's StatPlus ■
------
http://www.ViewMove.com |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |