Matlab GUI回调麻烦 [英] Matlab GUI callback troubles
问题描述
我尝试使uipanel更改边框颜色,同时在除输入和面板按钮之外的其他位置按下并释放鼠标按钮.
I try to make the uipanel change boarder colors while pressing and releasing mouse button on elsewhere except inputs and panel buttons.
function [oldpropvalues,varargout]=DisableFigure(handlearray,prop,propvalue,varargin);
oldpropvalues=get(handlearray,prop);
%this IF is used to highlight the "modal" panel when anywhere outside it is pressed
if length(varargin)==2
%these two are the old windowbutton functions which will be put back when the window is put back to normal.
varargout{1}=get(varargin{1},'windowbuttondownfcn');
varargout{2}=get(varargin{1},'windowbuttonupfcn');
set(varargin{1},'windowbuttondownfcn',['set(varargin{2},''bordertype'',''line'',''borderwidth'',2,''highlightcolor'',[0 0 0])']);
set(varargin{1},'windowbuttonupfcn',['set(varargin{2},''bordertype'',''beveledout'',''borderwidth'',1,''highlightcolor'',[1 1 1])']);
end
set(handlearray,prop,propvalue);
错误显示 未定义的变量"varargin"或类"varargin".
The error shows Undefined variable "varargin" or class "varargin".
评估图形WindowButtonDownFcn时出错
Error while evaluating Figure WindowButtonDownFcn
未定义的变量"varargin"或类"varargin".
Undefined variable "varargin" or class "varargin".
评估图形WindowButtonUpFcn时出错
Error while evaluating Figure WindowButtonUpFcn
推荐答案
您的问题是您正在定义匿名函数:
Your problem is that you're defining your window callbacks as character vectors, which are evaluated in the base workspace where the variable varargin
doesn't exist. You can define them as anonymous functions instead:
set(varargin{1}, 'WindowButtonDownFcn', ...
@(~, ~) set(varargin{2}, 'BorderType', 'line', 'BorderWidth', 2, ...
'HighlightColor', [0 0 0]));
set(varargin{1}, 'WindowButtonUpFcn', ...
@(~, ~) set(varargin{2}, 'BorderType', 'beveledout', 'BorderWidth', 1, ...
'HighlightColor', [1 1 1]));
这篇关于Matlab GUI回调麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!