different reactions to right/left click

6 ビュー (過去 30 日間)
Stepan Vecera
Stepan Vecera 2021 年 5 月 11 日
コメント済み: Stepan Vecera 2021 年 5 月 12 日
hi, i have array of buttons and i would like to have different reaction to right/left click. can i do it in one function? i have tried using selectiontype, but i cant figure it out myself
  2 件のコメント
Jan
Jan 2021 年 5 月 11 日
編集済み: Jan 2021 年 5 月 11 日
Are talking about figures or uifiguires? Did you create the GUI by code, GUIDE or AppDesigner? Please post the code you have tried and explain, which problems it has. Then it is much easier to suggest a solution. The less the readers have to guess, the more likely suggestions match your problem.
The EventData should allow you to distinguish the mouse keys.
Stepan Vecera
Stepan Vecera 2021 年 5 月 11 日
編集済み: Stepan Vecera 2021 年 5 月 12 日
sorry for not including that,
w=9;
h=9;
fig=figure;
panel = uipanel(fig, ...
'Units', 'normalized', ...
'Position', [0.1, 0.1, 0.7, 0.7]);
for iR=1:w
for iC = 1:h
button(iR, iC) = uicontrol(panel, ...
'Style', 'pushbutton', ...
'Units', 'normalized', ...
'Position', [(iC-1)*1/fS(2), 1-iR*1/fS(1), 1/fS(2), 1/fS(1)], ...
'String', ' ', ...
'Callback', @buttonPushed, ...
'Tag', ' ');
end
end
and i tried this. there is error:Unrecognized property SelectionType for class UIControl. i see, where is the problem, but i dont know how to solve it.
function buttonPushed(hObj, ~)
f=get(hObj, 'SelectionType')
if f=='alt'
hObj.String = sprintf('!')
else
if hObj.Tag == 'bom'
hObj.String=sprintf('bomb');
hObj.BackgroundColor='red';
else
hObj.String=hObj.Tag;
hObj.BackgroundColor=[0.3010 0.7450 0.9330];
end
end
end

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

採用された回答

Jan
Jan 2021 年 5 月 12 日
編集済み: Jan 2021 年 5 月 12 日
Comparing char vectors by == fails, if the number of characters is not equal.
'123' == 'abc' % Working
'1234' == '0' % Working, because 1 variable is a scalar
'12' == 'abc' % error
Use strcmp instead.
The SelectionType is a property of the figure:
function buttonPushed(hObj, ~)
hFig = ancestor(hObj, 'figure');
Selection = get(hFig, 'SelectionType')
if strcmp(Selection, 'alt')
...
end
  1 件のコメント
Stepan Vecera
Stepan Vecera 2021 年 5 月 12 日
thank you so much, you are the best!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConfigure Simulation Conditions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by