How to automatically resize custom button.CData image with maximize and restore down clicks on guide?
Afficher commentaires plus anciens
Hi,
I am trying to use cData feature to change the look of each button to some image.
I was able to acheive this but when I try to use maximize and restore down clicks on guide, the image size is not being updated to fit the normalized size of the button.
Can we make the button.CData resize the image when we do change the size of GUI using maximize or downclick or drag features on the guide?
My code:
I put the image fit to button size in OpeningFcn like this:
% --- Executes just before tempGUI is made visible.
function tempGUI_OpeningFcn(hObject, eventdata, handles, varargin)
handles = guidata(hObject);
[button_img,~]=imread('peppers.png');
handles.openPeppers.Units = 'pixels';
button_img =imresize(button_img,fliplr(handles.openPeppers.Position(1,3:4)));
handles.openPeppers.CData = button_img;
handles.openPeppers.Units ='normalized';
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
Then, if I change the size of guide manually , I need to dump the same code into button again to fit into button size.
% --- Executes on button press in openPeppers.
function openPeppers_Callback(hObject, eventdata, handles)
% hObject handle to openPeppers (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
button_img = handles.openPeppers.CData;
handles.openPeppers.Units = 'pixels';
button_img =imresize(button_img,fliplr(handles.openPeppers.Position(1,3:4)));
handles.openPeppers.CData = button_img;
handles.openPeppers.Units ='normalized';
% Update handles structure
guidata(hObject, handles);
Sample Images:
After OpeningFcn looks fine:

When I resize the guide manually, it doesn't fit and need to press button:

Can I do this without button click option?
Thanks,
Gopi
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!