How to determine cursor position in 'edit' uicontrol

17 views (last 30 days)
I have an application where there are several buttons that apply a specific function to the data. The user can also enter values in the edit box. However if the cursor is positioned in the edit box and a button is pressed the new function will apear at the end of the edit box and I need that this appear at cursor position how to do this?

Accepted Answer

Adam
Adam on 2 Mar 2016
Probably you would have to get the 'CurrentPoint' from the figure and compare this against the 'Position' property of the edit box. If the edit box is parented by some panel inside the figure then you would have to go a layer deeper and get the position of the panel and then the position of the edit box within the panel.
Since you would presumably need to test this a lot you can obviously calculate the position of the edit box relative to the figure (if it is inside a parent panel) and store it so that you can test the 'CurrentPoint' against it quickly.
In terms of actually putting text at a specific location within an edit box though I don't think this is possible (maybe using java) as you just set the 'String' property of the edit box and do not have control over its positioning within the edit box.
  1 Comment
Juan Ruiz
Juan Ruiz on 2 Apr 2023
Hi, I would like to know if there's a better way to do this on 2023. I'm using matlab app designer and I'm trying to insert text at the position of the cursor on a EditField by pushing a button. @Armindo and @Adam

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!