I have a TextArea, TextArea1, which has unstyled text already.
I Have a BevelButton that I can select a string of my choice.
I want that string to be inserted at a point where I will now click with the mouse.
I can do that with the use of the clipboard but I don’t want to use the clipboard.
I want something like this…
When I click in the already existing text, my app calculates the position at that point then add the selected text there.
In the MouseDown event of your TextArea1 do the following:
Sub MouseDown(x As Integer, y As Integer) As Boolean
Dim pos As Integer = Me.InsertionPosAtXY(x, y)
Me.Text = Me.Text.Mid(1, pos) + "text to add" + Me.Text.Mid(pos)
...
End Sub
Sub MouseDown(x As Integer, y As Integer) As Boolean
Dim pos As Integer = Me.InsertionPosAtXY(x, y)
Me.Text = Me.Text.Mid(1, pos) + “text to add” + Me.Text.Mid(pos)
…
End Sub
If I get your problem right you simply want to insert text into another string in a text area? But that is a piece of cake you’ll see! You don’t have to calculate anything thanks to general Windows textbox control properties which also apply here. Look at this example:
textfield1.text=“this is a simple text”
Here you want to insert "very " right before “simple”, and let this insertion text be part of the method behind your bevel button. Now all you need is to click into the text right before “simple”. Three properties dealing with selection will be set at this moment:
textfield1.SelStart = 10
textfield1.SelLength=0
textfield1.SelText=’’ (empty string)
You can overwrite all three properties none of them is readonly. So set SelText to "very " and schwupps! Xojo does all the work for you the text is correctly inserted without you having to calculate anything. How do you like that?