How can I make a textbox selectable?
이전 댓글 표시
I'm trying to trigger an event when a textbox is selected. If I manually set the "Selected" property to "on", the box is highlighted. But I can't figure out how to do this via user interaction.
Minimal example of the type of interface I'm trying to create:
f = figure;
a = axes(f);
foo = annotation('textbox','String','Foo','BackgroundColor','white');
bar = annotation('textbox','String','Bar','BackgroundColor','white');
somePlot = plot([1, 2],[1, 1]);
xlim([0 3])
ylim([0 2])
xscaled = (somePlot.XData - a.XLim(1))/(a.XLim(2) - a.XLim(1));
yscaled = (somePlot.YData - a.YLim(1))/(a.YLim(2) - a.YLim(1));
foo.Position(1:2) = [xscaled(1)*a.Position(3) + a.Position(1) - foo.Position(3)/2,...
yscaled(1)*a.Position(4) + a.Position(2) - foo.Position(4)/2];
bar.Position(1:2) = [xscaled(2)*a.Position(3) + a.Position(1) - bar.Position(3)/2,...
yscaled(2)*a.Position(4) + a.Position(2) - bar.Position(4)/2];
foo.Selected = 'on';
Ideally I'd like to be able to change the selected textbox with a mouse click. I've tried setting the PickableParts property to 'all' but that doesn't change anything.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!