Function to copy to clickboard in App Designer?
3 次查看(过去 30 天)
显示 更早的评论
I am making an application that outputs results in Edit Fields (both text and numeric). I would like to add a function that automatically copies the contents of an Edit Field to the clipboard when the Edit Field is selected (clicked). However, I do not see a callback function for Edit Fields like "ClickedFcn" for Drop Down lists.
Is it possible to do this directly or perhaps via some workaround?
2 个评论
dpb
2025-7-20
I've never gotten fancy enough to use them, but the workaround I can think of would be to put the control in a panel that does have the callback. How well it would suit your appication, I don't know...
采纳的回答
Matt J
2025-7-20
编辑:Matt J
2025-7-20
Implement a WindowButtonDownFcn callback for the UIFigure canvas,
function CanvasButtonDown(app, event)
clickedComponent = app.UIFigure.CurrentObject;
if clickedComponent == app.MyEditField
% This code runs when the edit field is clicked
disp('Edit field was clicked');
clipboard('copy' , app.MyEditField.Value);
end
end
3 个评论
Matt J
2025-7-21
编辑:Matt J
2025-7-21
I don't see any option for a CanvasButtonDown callback
Youi want to set the WindowButtonDownFcn callback in the Component browser (see below). 'CanvasButtonDown' is just a hypothetical name I assigned for the function signature. The name appearing in the function signature of a callback can be anything you want.

There seems to be an issue because the Edit FIeld in question is inside of a Grid Layout, which is itself inside of a Tab, which is in turn inside of a Tab Group.
Doesn't seem to be an issue for me. I've attached a minimal working example app to illustrate.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!