Copying from a textbox with IgnoreKey

BjornF

Active Member
Licensed User
Longtime User
I have a textbox with a content which I want to protect from accidental changes. For this I am using a text box with IgnoreKey.

However I would also like the user to be able to copy parts from that text. Unfortunately the IgnoreKey also makes the textbox ignore ctrl-C (although you can mark text with shift-arrow). Is there any easy solution to this that I have overlooked?

all the best / Björn
 

BjornF

Active Member
Licensed User
Longtime User
Stupid

:signOops:

Sorry, of course all you need to do is right click and then save... / Björn


Edit:
Filippo - that is very neat, I'll put that in as well (just for us who don't know how to use the right click), thanks
 

Leginus

Member
Licensed User
Longtime User
You can do it by creating your own copy and paste buttons and using the selstart and sellength property. Example attached

B4X:
Sub Globals
   'Declare the global variables here.
Dim CopyText
End Sub

Sub App_Start
   Form1.Show
   
End Sub


Sub TextBox1_KeyPress (key)
textbox1.IgnoreKey
End Sub

Sub btnCopy_Click
copyText=SubString(textbox1.text,textbox1.SelectionStart,textbox1.SelectionLength)
End Sub

Sub btnPaste_Click
textbox2.Text=copytext
End Sub
 

BjornF

Active Member
Licensed User
Longtime User
Thank you Leginus,
I can see that that is also a way of doing it, it's just that I'm a firm believer of standardisation and when you have learned that Ctrl-C copies the text in almost all applications it is very frustrating to encounter one in which it does not. ;)

I think Filippo's ReadOnly mode for the textbox is exactly what I was after.

all the best / Björn
 
Top