How to automatically show the last characters of a long string in a edit box?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dear all, i am using the GUI and when i set a edit string (set(handles.edit1,'String',str)) it appears from the beginning, but i'd like to show the last parto of the long string (it is a path and i would like to show the name of the selected file but showing all the path)
Can you plese help me?
2 comentarios
Geoff Hayes
el 13 de Ag. de 2016
Luigi - you could try https://www.mathworks.com/matlabcentral/answers/154589-how-to-automatically-scroll-a-textbox-to-end-of-line though now, two years later, I can't seem to get this code to work! :)
Respuestas (2)
Stalin Samuel
el 13 de Ag. de 2016
Get the file name and path name in separate variables and pass only the file name to the edit box
2 comentarios
Geoff Hayes
el 15 de Ag. de 2016
Stalin - please clarify how this will show the last characters of the long string in the edit box. And, what are the file and path name that you are referring to?
Stalin Samuel
el 16 de Ag. de 2016
Editada: Stalin Samuel
el 16 de Ag. de 2016
If you use the command
[FileName,PathName] = uigetfile('*.file extension','Select the file');
then name of the selected file will be stored in variable 'FileName'
Walter Roberson
el 16 de Ag. de 2016
Put the edit box inside a uipanel.
When you have written the string into the edit box, get the "extent" property of the edit box. That basically tells you how many pixels wide and high would be needed to render what is in the string.
Now using the information you extracted from the extent property, you can set the Position of the edit box relative to the uipanel so that the end of the text is visible inside the uipanel.
If the user is to be able to edit the contents of the box, then you will need a KeyPressCallback to re-run the calculation of the size. You would not be able to use click positioning to move around in the edit box without the code getting confused.
Caution: if you get the String property of the edit box while you are inside a KeyPressCallback then it will not reflect any changes made to the contents since the last time the edit box either had return pressed or lost focus. You need to keep track of all characters typed by the user including taking into account backspaces. And remember that if you are using a proportional font then you cannot just multiply number of characters by a width to figure out the number of pixels needed to render: you will need to toss the text into an edit box and ask for its extent (and then either hide or destroy the temporary edit box before it becomes visible to the user.)
0 comentarios
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!