Cut & Paste Scrolling issues

tsteward

Well-Known Member
Licensed User
Longtime User
With my code below I get annoying scroll action.

On a long page if I cut or paste My code scrolls to the end of the pasted text. If it is only one word it scrolls so as this word is at the bottom of the text box. If I don't set the scroll position I end up at the top.

How can I paste and not have the textbox move at all. If I press Control V it behaves as I want. However if I put the keydown, keypress code into the paste button nothing happens.

B4X:
Case 18 'btnPaste
  If TextEdit.SelectionStart > -1 Then
   i = TextEdit.SelectionStart
   If TextEdit.SelectionLength > 0 Then 'The pasted text should replace the selection.
     TextEdit.Text = StrRemove(TextEdit.Text,i,TextEdit.SelectionLength)
   End If
   If cPPC Then 'Paste from the clipboard on the device
     s = clip.GetClipboardData
   Else 'Paste from the global variable on the desktop
     s = DesktopString
   End If
   TextEdit.Text  = StrInsert(TextEdit.Text,i,s)
   TextEdit.SelectionStart = i + StrLength(s)
   TextEdit.ScrollToCaret
'    TextEdit.Focus
'    Hardware.KeyDown(17)
'    hardware.KeyPress(Asc("V"))
'    hardware.KeyUp(17)
  End If
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Setting the textbox text property will reset the caret position.
However the following code works fine:
B4X:
Sub Globals
    'Declare the global variables here.

End Sub

Sub App_Start
    Form1.Show
    hardware.New1
End Sub

Sub Button1_Click 'cut
    textbox1.Focus
    hardware.KeyDown(17)
    hardware.KeyPress(Asc("X"))
    hardware.KeyUp(17)
End Sub

Sub Button2_Click 'Paste
    textbox1.Focus
    hardware.KeyDown(17)
    hardware.KeyPress(Asc("V"))
    hardware.KeyUp(17)
End Sub
 

tsteward

Well-Known Member
Licensed User
Longtime User
Gday Erel,
As you can see by my commented out code above I did try that. Unfortunately it doesn't work. Not in my program anyway.

Thanks for your ever vigilant watch over this forum. Your a good person to deal with & what you charge for B4PPC is not enough for the support you give.

Thanks
 

agraham

Expert
Licensed User
Longtime User
test the attached program on your device and tell me if it worked or not.
Am I being stupid :confused: That program does nothing on my Axim X30 (WM2003SE), nor my HTC Diamond (WM6.0) nor my HP iPAG214 (WM6.1)! It's so simple, I copied 1.sbp and the Hardware.dll to the device and ran the program in the IDE, selected some text, pressed Cut - nothing! Ctl-X and Ctl-V on the SIP work fine.

EDIT :- You've left the Textbox1.Focus statements out Erel :signOops:
 
Last edited:
Top