How to automatically show the last characters of a long string in a edit box?

4 ビュー (過去 30 日間)
Luigi Bruno
Luigi Bruno 2016 年 8 月 11 日
回答済み: Walter Roberson 2016 年 8 月 16 日
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 件)

Stalin Samuel
Stalin Samuel 2016 年 8 月 13 日
Get the file name and path name in separate variables and pass only the file name to the edit box
  2 件のコメント
Geoff Hayes
Geoff Hayes 2016 年 8 月 15 日
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
Stalin Samuel 2016 年 8 月 16 日
編集済み: Stalin Samuel 2016 年 8 月 16 日
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
Walter Roberson 2016 年 8 月 16 日
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.)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by