AppDesigner - Changing EditField font size
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Abdullah Wasi
el 23 de Mayo de 2021
Comentada: Abdullah Wasi
el 27 de Mayo de 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 comentario
Respuesta aceptada
Adam Danz
el 24 de Mayo de 2021
Editada: Adam Danz
el 26 de Mayo de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Develop Apps Using App Designer 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!