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!