7-5 ?M 檔?設?滑?事件????

b]p GUI ɡAdUOѤFƹnʡAziH]p@ӹϧεAϱoƹbϧΪUʧ@]٬uƹƥv Mouse EventsAҦpUƹsBʷƹƹs^AiHIJo@sꪺOAFznĪGC

b]wƹƥ󪺤OɡA̬ʽ謰G

  1. WindowButtonDownFcnGƹsUɤO
  2. WindowButtonMotionFcnGƹʮɪO
  3. WindowButtonUpFcnGƹsɪO

oǩʽ賣Oݩ@ӹϧεA]AL̳WdFbϧεUAUƹƥ󪺤OC

@ӨAڭ̧ƱƹQUAMAʷƹɡA~|IJoʮɪOCF즹ĪGAڭ̥UCƶG

]AubƹsQUABƹbʮɡA WindowButtonMotionFcn O~|QIsC

HUڭ̥Τ@²檺ҤlӻCboӨҤlAƹƥ|ͤUCG

dҦpUG

Example 1: 07-⦡ϧλPGUI]p/mouse01.mfunction mouse01(action) % mouse01: Үiܦp]wƹƥ󪺤O, based on "switchyard programming" % Roger Jang, 20040405 if nargin<1, action='start'; end switch(action) case 'start' % }ҹϧε axis([0 1 0 1]); % ]w϶bd box on; % N϶b[WϮ title('Click and drag your mouse in this window!'); % ]wƹsQUɪOumouse01 downv set(gcf, 'WindowButtonDownFcn', 'mouse01 down'); case 'down' % ƹsQUɪO % ]wƹʮɪOumouse01 movev set(gcf, 'WindowButtonMotionFcn', 'mouse01 move'); % ]wƹsQɪOumouse01 upv set(gcf, 'WindowButtonUpFcn', 'mouse01 up'); % CLuMouse down!vT fprintf('Mouse down!\n'); case 'move' % ƹʮɪO currPt = get(gca, 'CurrentPoint'); x = currPt(1,1); y = currPt(1,2); line(x, y, 'marker', '.'); % CLuMouse is moving!vTηƹ{bm fprintf('Mouse is moving! Current location = (%g, %g)\n', x, y); case 'up' % ƹsQɪO % MƹʮɪO set(gcf, 'WindowButtonMotionFcn', ''); % MƹsQɪO set(gcf, 'WindowButtonUpFcn', ''); % CLuMouse up!vT fprintf('Mouse up!\n'); end

Wzdҥuܤ@ӪťյAziHbiƹIΩ즲AYibƹI諸m͹ϧΡG


MATLAB{]pGJg