How can I change the font size of MsgBox?
42 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
if f==0 || f <0
Message = sprintf('Serbestlik derecesi %d\n DENGELEME YOK!!! ',f);
h = msgbox(Message,...
'Dikkat', 'warn');
end
0 comentarios
Respuestas (2)
Anibal Siguenza Torres
el 20 de Ag. de 2018
Editada: Anibal Siguenza Torres
el 20 de Ag. de 2018
The easiest is to use the TeX format so the subset of markup supported by matlab can be used. To activate them you have to create an structure and send it as parameter as follows:
CreateStruct.Interpreter = 'tex';
CreateStruct.WindowStyle = 'modal';
msgbox('\fontsize{18} Now is big =)', CreateStruct)
1 comentario
Adam Danz
el 26 de Jun. de 2018
Editada: Adam Danz
el 20 de Ag. de 2018
Here's a function I wrote that does exactly this. Pass the handle of the msgbox() and the fontsize to the function.
If you don't want a function, here's the basics:
First get the handle to the text within the message box, then change the font size. Here's a demo.
mh = msgbox('I can barely read this.', 'test'); %create msgbox
th = findall(mh, 'Type', 'Text'); %get handle to text within msgbox
th.FontSize = 14; %Change the font size
If you increase the font size too much, you'll need to expand the message box to fit the extent of the text.
deltaWidth = sum(th.Extent([1,3]))-mh.Position(3) + th.Extent(1);
deltaHeight = sum(th.Extent([2,4]))-mh.Position(4) + 10;
mh.Position([3,4]) = mh.Position([3,4]) + [deltaWidth, deltaHeight];
Lastly, allow the user to resize the window if needed:
mh.Resize = 'on';
2 comentarios
Julia
el 17 de Jul. de 2025
Editada: Julia
el 17 de Jul. de 2025
This is an old thread, but I still had the same issue these days. Thank you, Adam, for your suggestion! Based on this, I have slightly extended the code so that also the 'Okay' button changes size and that the 'Okay' button is recentered in the message box and the message box on the screen.
This is the function (usage example underneath):
function [] = ResizeTextMessagebox(mb, fontsize)
% Determine relative font size change
defaultFontSize = get(0,'FactoryUicontrolFontSize');
diffSize = 1.5*(fontsize - defaultFontSize);
% Find text object
th = findall(mb, 'Type', 'Text'); % Get handle to text within msgbox
th.FontSize = fontsize; % Change the font size
% If you increase the font size too much, you'll need to expand the message box to fit the extent of the text.
deltaWidth = sum(th.Extent([1,3]))-mb.Position(3) + th.Extent(1);
deltaHeight = sum(th.Extent([2,4]))-mb.Position(4) + diffSize;
mb.Position([3,4]) = mb.Position([3,4]) + [deltaWidth, deltaHeight];
% Recenter the box left to right
mb.Position(1) = mb.Position(1) - deltaWidth/2;
% Identify the 'Okay' Button
button = findall(mb,'Type','UIControl');
% Adjust the font size of the 'Okay' Button accordingly
button.FontSize = fontsize;
% Resize the 'Okay' Button accordingly
mb.Position(4) = mb.Position(4) + diffSize;
% Increase the height of the 'Okay' button accordingly
button.Position(4) = button.Position(4) + min(diffSize,5);
button.Position(3) = button.Position(3) + min(diffSize,5);
% Reposition the 'Okay' Button
button.Position(1) = (mb.Position(3)-button.Position(3))/2;
% Move text slightly up
th.Position(2) = th.Position(2) + diffSize;
% Lastly, allow the user to resize the window if needed:
mb.Resize = 'on';
end
Usage example:
fontsize = 16;
mb = msgbox('Here is a bit of text for testing.');
ResizeTextMessagebox(mb, fontsize);
% Optional if you want to block execution until user clicks 'Okay':
uiwait(mb);
Ver también
Categorías
Más información sobre Characters and Strings 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!