AppDesigner - Changing EditField font size
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Abdullah Wasi
le 23 Mai 2021
Commenté : Abdullah Wasi
le 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 commentaire
Réponse acceptée
Adam Danz
le 24 Mai 2021
Modifié(e) : Adam Danz
le 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!