GUI相应鼠标事件

  1 function varargout = GUI18(varargin)
  2 % GUI18 MATLAB code for GUI18.fig
  3 %      GUI18, by itself, creates a new GUI18 or raises the existing
  4 %      singleton*.
  5 %
  6 %      H = GUI18 returns the handle to a new GUI18 or the handle to
  7 %      the existing singleton*.
  8 %
  9 %      GUI18('CALLBACK',hObject,eventData,handles,...) calls the local
 10 %      function named CALLBACK in GUI18.M with the given input arguments.
 11 %
 12 %      GUI18('Property','Value',...) creates a new GUI18 or raises the
 13 %      existing singleton*.  Starting from the left, property value pairs are
 14 %      applied to the GUI before GUI18_OpeningFcn gets called.  An
 15 %      unrecognized property name or invalid value makes property application
 16 %      stop.  All inputs are passed to GUI18_OpeningFcn via varargin.
 17 %
 18 %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
 19 %      instance to run (singleton)".
 20 %
 21 % See also: GUIDE, GUIDATA, GUIHANDLES
 22 
 23 % Edit the above text to modify the response to help GUI18
 24 
 25 % Last Modified by GUIDE v2.5 24-Jan-2018 09:07:12
 26 
 27 % Begin initialization code - DO NOT EDIT
 28 gui_Singleton = 1;
 29 gui_State = struct('gui_Name',       mfilename, ...
 30                    'gui_Singleton',  gui_Singleton, ...
 31                    'gui_OpeningFcn', @GUI18_OpeningFcn, ...
 32                    'gui_OutputFcn',  @GUI18_OutputFcn, ...
 33                    'gui_LayoutFcn',  [] , ...
 34                    'gui_Callback',   []);
 35 if nargin && ischar(varargin{1})
 36     gui_State.gui_Callback = str2func(varargin{1});
 37 end
 38 
 39 if nargout
 40     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
 41 else
 42     gui_mainfcn(gui_State, varargin{:});
 43 end
 44 % End initialization code - DO NOT EDIT
 45 
 46 
 47 % --- Executes just before GUI18 is made visible.
 48 function GUI18_OpeningFcn(hObject, eventdata, handles, varargin)
 49 % This function has no output args, see OutputFcn.
 50 % hObject    handle to figure
 51 % eventdata  reserved - to be defined in a future version of MATLAB
 52 % handles    structure with handles and user data (see GUIDATA)
 53 % varargin   command line arguments to GUI18 (see VARARGIN)
 54 
 55 % Choose default command line output for GUI18
 56 handles.output = hObject;
 57 
 58 global ButtonDown pos1;
 59 ButtonDown = [];
 60 pos1 = [];
 61 
 62 
 63 % Update handles structure
 64 guidata(hObject, handles);
 65 
 66 % UIWAIT makes GUI18 wait for user response (see UIRESUME)
 67 % uiwait(handles.figure1);
 68 
 69 
 70 % --- Outputs from this function are returned to the command line.
 71 function varargout = GUI18_OutputFcn(hObject, eventdata, handles) 
 72 % varargout  cell array for returning output args (see VARARGOUT);
 73 % hObject    handle to figure
 74 % eventdata  reserved - to be defined in a future version of MATLAB
 75 % handles    structure with handles and user data (see GUIDATA)
 76 
 77 global ButtonDown pos1;
 78 if strcmp(get(gcf,'SelectionType'),'normal')
 79     ButtonDown = 1;
 80     pos1 = get (handles.axes1,'CurrentPoint');
 81 end
 82 
 83 
 84 % Get default command line output from handles structure
 85 varargout{1} = handles.output;
 86 
 87 
 88 % --- Executes on mouse motion over figure - except title and menu.
 89 function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
 90 % hObject    handle to figure1 (see GCBO)
 91 % eventdata  reserved - to be defined in a future version of MATLAB
 92 % handles    structure with handles and user data (see GUIDATA)
 93 
 94 global ButtonDown pos1
 95 
 96 if ButtonDown == 1
 97     pos = get (handles.axes1,'CurrentPoint');
 98     line([pos1(1,1) pos(1,1)],[pos1(1,2) pos(1,2)],'LineWidth',4);
 99     pos1=pos;
100 end
101 
102 
103 % --- Executes on key release with focus on figure1 or any of its controls.
104 function figure1_WindowKeyReleaseFcn(hObject, eventdata, handles)
105 % hObject    handle to figure1 (see GCBO)
106 % eventdata  structure with the following fields (see MATLAB.UI.FIGURE)
107 %    Key: name of the key that was released, in lower case
108 %    Character: character interpretation of the key(s) that was released
109 %    Modifier: name(s) of the modifier key(s) (i.e., control, shift) released
110 % handles    structure with handles and user data (see GUIDATA)
111 
112 
113 % --- Executes on mouse press over figure background, over a disabled or
114 % --- inactive control, or over an axes background.
115 function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
116 % hObject    handle to figure1 (see GCBO)
117 % eventdata  reserved - to be defined in a future version of MATLAB
118 % handles    structure with handles and user data (see GUIDATA)
119 global ButtonDown 
120 ButtonDown = 0 ;
View Code

画线:

 

转载于:https://www.cnblogs.com/shixinzei/p/8339903.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值