Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How do you select text in a memo field?
Message
 
 
À
09/08/2006 03:25:15
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01144007
Message ID:
01144338
Vues:
18
>>How do you select text in a memo field?
>>
>>I am trying to select eveything from the current mouse position to the end. It works if you don't type in new text.
>>
>>I created a simple form with an Editbox having a memo field as its control source. On the form is a button that has this in the click().
>>
>>
>>
>>	PROCEDURE command1.Click
>>		With Thisform.Edit1
>>			nStart = .SelStart
>>			nEnd = Len(.Value)
>>
>>			.SelStart = nStart
>>			.SelLength = nEnd - nStart
>>			.SetFocus()
>>		Endwith
>>	ENDPROC
>>
>>
>>
>>If the memo field already has data, one can click anywhere in the memo field, and then on the button. The text from the current position to the end is highlighted correctly.
>>
>>Now in the memo field try adding new data. Press Enter twice and then type some text. Position the mouse somewhere in the new text and click in the meo field. Now click the button. Notice that the selected text is not correct.
>>
>>How can I get the desired selection to show correctly (from the position of the last click to the end)?
>>
>>Cyril
>
>Set editbox.HideSelection = .F.
>
>example
>
>PUBLIC oform1
>
>oform1=NEWOBJECT("form1")
>oform1.Show
>RETURN
>
>DEFINE CLASS form1 AS form
>
>	Height = 525
>	Width = 630
>	DoCreate = .T.
>	Caption = "Form1"
>	Name = "Form1"
>
>
>	ADD OBJECT edit1 AS editbox WITH ;
>		Height = 210, ;
>		HideSelection = .F., ;
>		Left = 78, ;
>		Top = 127, ;
>		Width = 261, ;
>		ControlSource = "tt.mm", ;
>		Name = "Edit1"
>
>
>	ADD OBJECT command1 AS commandbutton WITH ;
>		Top = 49, ;
>		Left = 85, ;
>		Height = 27, ;
>		Width = 84, ;
>		Caption = "Command1", ;
>		Name = "Command1"
>
>
>	PROCEDURE Load
>		CREATE CURSOR tt (mm memo)
>		APPEND BLANK
>		replace mm WITH "some text"+CHR(13)+"other"
>	ENDPROC
>
>
>	PROCEDURE command1.GotFocus
>		this.Caption = thisform.edit1.SelText
>	ENDPROC
>
>
>ENDDEFINE
>
Fabio
Thanks for your suggestion. Unfortunately it did not solve the problem. Modifying your code slightly:
Public oform1

oform1=Newobject("form1")
oform1.Show
Return

Define Class form1 As Form

	Height = 525
	Width = 630
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"


	Add Object edit1 As EditBox With ;
		Height = 210, ;
		HideSelection = .F., ;
		Left = 78, ;
		Top = 127, ;
		Width = 261, ;
		ControlSource = "tt.mm", ;
		Name = "Edit1"


	Add Object command1 As CommandButton With ;
		Top = 49, ;
		Left = 85, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Command1", ;
		Name = "Command1"


	Procedure Load
	Create Cursor tt (mm Memo)
	Append Blank
	Replace mm With "some text"+Chr(13)+"other"
Endproc


*!*		PROCEDURE command1.GotFocus
*!*			this.Caption = thisform.edit1.SelText
*!*		ENDPROC

	Procedure command1.Click
	With Thisform.edit1
		nStart = .SelStart
		nEnd = Len(.Value)

		.SelStart = nStart
		.SelLength = nEnd - nStart
		.SetFocus()
	Endwith
Endproc


Enddefine
(Note for Dan:- the SetFocus is there, tried it in a few places, doesn't help).

Run the prg. Click somewhere in the middle of the word "other", then click the button. Notice that everything from where you were to the end is selected correctly.

Now at the end of "other" press enter twice. Then type "apple red".

Now click between the two p's in apple, then click the button.

I am expecting the text from p to the end to be selected, but I observe something different. Do you see the unexpected outcome also?

BTW I tried in vfp7, 8 and 9 and the same bad behaviour happens in all versions. I am looking for a fix for a vfp7 application.


Any ideas?

Cyril
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform