首页 > 解决方案 > 如何操作按钮位置属性?

问题描述

我正在努力调整按钮位置。不应该那么难,但不知何故我无法弄清楚。任何想法在哪里添加正确的代码?

button = 'Continue';

while strcmpi(button, 'Continue')

promptMessage = sprintf('Are the results ok?,\nor should the script be stopped?');
    titleBarCaption = 'Continue?';
    button.Position = [100 100 50 20];                    %this line seems to the issue
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');

if strcmpi(button, 'Cancel')
break;
end
end

标签: matlabbutton

解决方案


这是一个在提示中按 continue 时随机将 auibutton放入 a的示例。这里被命名并且独立于 char 向量。由于问题中的详细信息有限,我不确定您是否尝试更改提示中按钮的位置。uifigurequestdlguibuttonTest_Buttonbuttonquestdlg

UI_Figure = uifigure;
UI_Figure.Position = [0 0 500 500];
Test_Button = uibutton('Parent',UI_Figure);

Figure_Width = UI_Figure.Position(3);
Figure_Height = UI_Figure.Position(4);

button = 'Continue';

while strcmpi(button, 'Continue')

promptMessage = sprintf('Are the results ok?,\nor should the script be stopped?');

titleBarCaption = 'Continue?';
Test_Button.Position = [round(rand(1)*Figure_Width) round(rand(1)*Figure_Height) 50 20];                    

%this line seems to the issue
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');

if strcmpi(button, 'Cancel')
break;
end

end

推荐阅读