How can I change the font size of MsgBox?
43 ビュー (過去 30 日間)
古いコメントを表示
if f==0 || f <0
Message = sprintf('Serbestlik derecesi %d\n DENGELEME YOK!!! ',f);
h = msgbox(Message,...
'Dikkat', 'warn');
end
0 件のコメント
回答 (2 件)
Anibal Siguenza Torres
2018 年 8 月 20 日
編集済み: Anibal Siguenza Torres
2018 年 8 月 20 日
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)
Adam Danz
2018 年 6 月 26 日
編集済み: Adam Danz
2018 年 8 月 20 日
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 件のコメント
Julia
2025 年 7 月 17 日
編集済み: Julia
2025 年 7 月 17 日
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);
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!