我想实现一些代码,以便当用户调整窗口大小时可以调用一个函数。我正在使用matlab 2018,他们建议使用SizeChangedFcn而不是ResizeFcn。我并没有过多地处理回调,但是我很难让我的GUI每次调整窗口大小时都调用SizeChangedFcn。 Currenlty,根本没有调用该函数。
function varargout = firstgui(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @firstgui_OpeningFcn, ...
'gui_OutputFcn', @firstgui_OutputFcn, ...
'SizeChangedFcn', @resizeui, ... % <-- added this line
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function resizeui(hObject,event)
disp("Hi");
编辑:
我应该提到我使用的程序严重依赖于指南,因此我坚持使用该实现。
这是“ gui_mainfcn”中的内容
function varargout = gui_mainfcn(gui_State, varargin)
% GUI_MAINFCN Support function for creation and callback dispatch of GUIDE GUIs.
% GUI_MAINFCN is called from inside MATLAB code files generated by GUIDE to handle
% GUI creation, layout, and callback dispatch.
%
% See also: GUIDE.
% GUI_MAINFCN provides these command line APIs for dealing with GUIs
%
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs
% are
% applied to the GUI before untitled_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
% Copyright 1984-2015 The MathWorks, Inc.
gui_StateFields = {'gui_Name'
'gui_Singleton'
'gui_OpeningFcn'
'gui_OutputFcn'
'SizeChangedFcn' %added this line as well does not work yet
'gui_LayoutFcn'
'gui_Callback'};
答案 0 :(得分:0)
我在这里找到了解决方法:
https://www.mathworks.com/help/matlab/creating_guis/gui-options.html
通过选择“工具”>“ GUI选项”,从GUIDE布局编辑器访问对话框。
其他(使用SizeChangedFcn)—对UI进行编程,以便在用户调整图形窗口的大小时以某种方式运行。
在gui选项中选择“ SizeChangedFcn”时,它为我创建了一个函数。
function figure1_SizeChangedFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp("Hi");