AppDesigner - Changing EditField font size
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Abdullah Wasi
am 23 Mai 2021
Kommentiert: Abdullah Wasi
am 27 Mai 2021
Hi! I wanted to change the font size of an edit field while running the program by selecting the value from the drop down list. This is the event function:
function FontSizeDropDownValueChanged(app, event)
value = app.FontSizeDropDown.Value;
switch value
case 8
app.EditField.FontSize = 8;
case 10
app.EditField.FontSize = 10;
case 12
app.EditField.FontSize = 12;
case 14
app.EditField.FontSize = 14;
case 16
app.EditField.FontSize = 16;
end
app.EditField.Value = value;
end
and this is the idea:
However, when I select a value the font size doesn't change. The text does change, but not the font size. What mistake am I making?
1 Kommentar
Akzeptierte Antwort
Adam Danz
am 24 Mai 2021
Bearbeitet: Adam Danz
am 26 Mai 2021
My guess is that your list of font sizes are strings and the value returned to the callback function is a string. Since it's a string it's not matching any of the cases in the switch/case so the fontsize never changes.
Option 1 is to convert the string to a number using str2double.
Option 2 is to define the dropdown ItemsData property as numbers, not strings. Then the Value will return a string. See properties for more info.
Lastly, stop using a switch case. Assign the fontsize directly
function FontSizeDropDownValueChanged(app, event)
value = app.FontSizeDropDown.Value;
app.EditField.FontSize = value; % or str2double(value) depending on which option you choose
app.EditField.Value = value; % or num2str(value) if a string is needed.
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!