How can I make a textbox selectable?
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!