How do I change the msgbox window size?

조회 수: 164 (최근 30일)
Nimrodb
Nimrodb 2013년 2월 19일
댓글: Image Analyst 2022년 5월 18일
I use the following command:
msgbox({'* long message that gets cut to two lines due to the length of it,...
'************************************************* '},...
'Help/Instructions','help');
Is there an option to define the size of the message box window that opens up?

답변 (4개)

Andrew Davies
Andrew Davies 2015년 9월 16일
You can use handles,
h = msgbox('long message that gets cut to two lines due to the length of it');
set(h, 'position', [100 440 1000 100]); %makes box bigger
ah = get( h, 'CurrentAxes' );
ch = get( ah, 'Children' );
set( ch, 'FontSize', 20 ); %makes text bigger
  댓글 수: 1
Jan
Jan 2018년 5월 12일
"Size of the message box window" does not mean the font size.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2013년 2월 19일
I don't believe so. You also cannot change the font size, which I've told them about. But you can use sprintf() to control where the line breaks occur.
  댓글 수: 4
Nimrodb
Nimrodb 2013년 2월 20일
I liked my option better -
msgbox({'Line1','Line2','Line3'});
But as I stated - If a line is longer than x chars - it automatically moves to the next line...
Image Analyst
Image Analyst 2013년 2월 20일
That's fine, though I think it gets more cluttered if you need to embed the values of variables at various locations in your strings, with having to stop the string, insert num2str(), and then starting the string again. And as I stated, I'm pretty sure there's no way to override what msgbox thinks is the longest width it can handle, unless you want to create your own GUI to replace it.

댓글을 달려면 로그인하십시오.


Luke Perry
Luke Perry 2018년 5월 12일
편집: Luke Perry 2018년 5월 12일
For those wishing to modify fontsize on msgboxes with images on them use the following:
h = msgbox('fgsdf','sdfsd','error');
object_handles = findall(h);
set( object_handles(6), 'FontSize', 20)
You may need to check the index for your own msgbox. If you want to change another property, such as textalignment of text, etc. simply call other properties of the text in the set() command (see below). MATLAB has this as a text object, so the properties of it differ from a normal object in which a person can call a position argument.
h = msgbox('fgsdf','sdfsd','error');
object_handles = findall(h);
set( object_handles(6), 'FontSize', 20, 'HorizontalAlignment', 'left', ...
'VerticalAlignment', 'bottom')
What is odd about this is MATLAB apparently has the vertical and horizontal alignments reversed... So when calling this it actually aligns to the top and right of the textbox the text is in. I may be missing something going on with how the position is determined by MATLAB.
  댓글 수: 4
Eric Crump
Eric Crump 2022년 5월 18일
Thanks! The way we have the file structure set up, I am realy trying not to have a seperate function but something more inside the code itself.
Image Analyst
Image Analyst 2022년 5월 18일
You can do that but I think it would be very messy everytime you just wanted to call something like msgbox because all that stuff about creating the CreateStruct would be in there. If you just want the window wider, you can do that from the main msgbox() function without a CreateStruct.

댓글을 달려면 로그인하십시오.


CS MATLAB
CS MATLAB 2016년 11월 26일
편집: Walter Roberson 2016년 11월 26일
This code doesn't work if it has an image on the message box.
Code:
[myicon,map] = imread('image.jpg');
prompt={data};
h = msgbox(prompt,'Success','custom',myicon,map);
%h = msgbox(prompt); --- Works perfectly fine
set(h, 'position', [100 300 400 120]); %makes box bigger
ah = get( h, 'CurrentAxes' );
ch = get( ah, 'Children' );
set( ch, 'FontSize', 15 ); %makes text bigger
  댓글 수: 2
jinyang huang
jinyang huang 2017년 7월 18일
Hi, after applying this how can I keep the text at the center
Luke Perry
Luke Perry 2018년 5월 12일
@jinyang, see the answer I submitted below. Although text objects are a little tricky as they are not treated as "normal" objects, so unless you create a msgbox yourself by making a new figure and placing axes on it, you will need to use the alignment properties.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by