How to exit zoom mode by shortcut in my own GUI?

2 ビュー (過去 30 日間)
Albert Bing
Albert Bing 2020 年 1 月 27 日
編集済み: Albert Bing 2020 年 1 月 27 日
I wrote a GUI program, in which the zoom operation was frequently used. So I defined a KerPressFcn “ctrl+=” which was the "zoom on" operation. See the following function myfunc1.
But how should I define a shortcut to exit zoom mode? It seems that zoom off in the function just doesn't work.
But in the other hand, in the command window, if input
figure; plot(1:10)
a figure shows. Then in the command window, input
zoom on
the cursor is in zoom mode in the figure;
Back in the command window, type
zoom off
then in the figure, the cursor exits the zoom mode.
Why did NOT the same command zoom off in my own function work?
My own function: (I revised the code to be more specific)
function myfunc1(fig)
fig.KeyPressFcn = @zoomKeys;
hAxes = axes(fig);
% some codes
plot(1:10);
function zoomKeys(~, event)
if strcmp(event.Modifier, 'control')
if ~strcmpi(event.Key, 'equal') % I want to exit the zoom mode.
zoom(fig, 'off');
end
switch event.Key
case 'equal' %'='
zoom(fig, 'on');
case '0'
zoom(fig, 'out');
end
end
end
end
  2 件のコメント
Rik
Rik 2020 年 1 月 27 日
I'm on mobile so I can't test the code, but you should probably use explicit handles in the zoom function.
Albert Bing
Albert Bing 2020 年 1 月 27 日
Use zoom(gcf, 'off') or zoom(fig, 'off') instead if just zoom off
I tried, but it didn't work.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by