フィルターのクリア

uicontextmenu interactions with GUI

2 ビュー (過去 30 日間)
Jerry Gregoire
Jerry Gregoire 2014 年 1 月 28 日
回答済み: Jerry Gregoire 2014 年 1 月 28 日
I have a GUI and when I right click a ui for the uicontext menu, I want to call a general callback for processing. To do this I need to know which UI triggered the callback. Currently I have This in my ui_CreateFcn:
hcmenu = uicontextmenu;
uimenu(hcmenu, 'label' , 'fdatool', 'callback', 'UI_callbackHandler(handles)');
set(hObject, 'uicontextmenu', hcmenu)
Where handles are in the base, (0). Is there a way that I can find which ui in my GUI triggered the call. Right now I am creating different functions in each UI. For example:
____
...
uimenu(hcmenu, 'label' , 'Name', 'callback', 'UI_callbackHandler1(handles)');
...
____
...
uimenu(hcmenu, 'label' , 'Name', 'callback', 'UI_callbackHandler2(handles)');
...
______
and so on. It is cumbersome Since the callbacks are very similar.

採用された回答

Jerry Gregoire
Jerry Gregoire 2014 年 1 月 28 日
Just figured good way to do it.
I tried passing the calling object's handle: ... uimenu(hcmenu, 'label' , 'Name', 'callback', UI_callbackHandler(hObject, handles)'); ...
But that is not available during execution. But I can pass a string, I chose the UI Tag
UITag = get(hObject, 'tag');
hcmenu = uicontextmenu;
uimenu(hcmenu, 'label' , 'Name', 'callback', ['UI_callbackHandler(''' UITag ''', handles)']);
set(hObject, 'uicontextmenu', hcmenu)
Now in my callback the first arg is the tag of the UI that tripped the callback.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 1 月 28 日
If you use the function handle variety of callback, then it will be passed two extra arguments automatically, the first of which is the handle of the object that it is being called on behalf of. You can identify that for your purposes in a variety of ways, including through the Tag or through the UserData

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by