AppDesigner - Changing EditField font size
9 次查看(过去 30 天)
显示 更早的评论
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?
采纳的回答
Adam Danz
2021-5-24
编辑:Adam Danz
2021-5-26
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!