如何得知memo上的字被選取 |
|
aconxu
一般會員 ![]() ![]() 發表:18 回覆:41 積分:11 註冊:2006-12-19 發送簡訊給我 |
|
Stallion
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
//---------------------------------------------------------------------------
#include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { if ( this->Memo1->SelLength > 0 ) ShowMessage(this->Memo1->SelText); } //--------------------------------------------------------------------------- |
aconxu
一般會員 ![]() ![]() 發表:18 回覆:41 積分:11 註冊:2006-12-19 發送簡訊給我 |
|
pcboy
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:177 回覆:1838 積分:1463 註冊:2004-01-13 發送簡訊給我 |
|
aconxu
一般會員 ![]() ![]() 發表:18 回覆:41 積分:11 註冊:2006-12-19 發送簡訊給我 |
|
axsoft
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:681 回覆:1056 積分:969 註冊:2002-03-13 發送簡訊給我 |
請先在Form1上放入Memo1及Popmenu1 , 然後將Memo1的Popmenu屬性設為Popmenu1
下面的Code你試試吧! unit1.H //--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include < Classes.hpp > #include < Controls.hpp > #include < StdCtrls.hpp > #include < Forms.hpp ><br />#include < Menus.hpp > #include < Clipbrd.hpp > //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TMemo *Memo1; TPopupMenu *PopupMenu1; TMenuItem *Copy; TMenuItem *N1; TMenuItem *Patse; void __fastcall FormCreate(TObject *Sender); void __fastcall CopyClick(TObject *Sender); void __fastcall PatseClick(TObject *Sender); void __fastcall FormShow(TObject *Sender); private: // User declarations void __fastcall AppMessage(tagMSG &Msg, bool &Handled); public: // User declarations __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif Unit1.CPP //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled) { if(Msg.message==WM_MOUSEMOVE){ if( Memo1->SelLength > 0 ) Copy->Visible=true; else Copy->Visible=false; } } void __fastcall TForm1::FormCreate(TObject *Sender) { Application->OnMessage = AppMessage; } //--------------------------------------------------------------------------- void __fastcall TForm1::CopyClick(TObject *Sender) { Clipboard()->Clear(); Clipboard()->SetTextBuf(Memo1->SelText.c_str()); Patse->Visible=true; } //--------------------------------------------------------------------------- void __fastcall TForm1::PatseClick(TObject *Sender) { if( Clipboard()->HasFormat(CF_TEXT) == true ) { char TextBuf[MAX_PATH 1]; Clipboard()->GetTextBuf( TextBuf, MAX_PATH ); Memo1->SelText = TextBuf; Patse->Visible=false; } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormShow(TObject *Sender) { Copy->Visible=false; Patse->Visible=false; } --------------------------------------------------------------------------- |
nickcai2002
一般會員 ![]() ![]() 發表:3 回覆:20 積分:24 註冊:2004-11-18 發送簡訊給我 |
利用事件 =>(1)Memo1KeyUp (2)Memo1MouseUp 應該能解決你的問題
ex: void __fastcall TForm1::Memo1KeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { Label1->Caption=Memo1->SelLength; //使用方式和pcboy2一樣 } void __fastcall TForm1::Memo1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Memo1KeyUp(Sender,0,Shift); } ===================引 用 文 章=================== 感謝~pcboy2 我試過了~好像不行 因為 選取memo上的 字並不會觸發 Memo1Change 只有在memo上key字就會觸發 Memo1Change 些時this->Memo1->SelLength =0 (因為我還沒選取字) 所以不會有ShowMessage出現 |
aconxu
一般會員 ![]() ![]() 發表:18 回覆:41 積分:11 註冊:2006-12-19 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |