How can I change pushbutton background
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Tarcisio
el 10 de Dic. de 2014
Respondida: Daniel
el 10 de Dic. de 2014
I constructed a number of pushbuttons by using the below loop, and now I want to change the background of each one when it was pressed.
for i = 1 : 8
for j = 1 : 7
btn(j,i) = uicontrol('Parent', figure_handle, ...
'Style', 'pushbutton', ...
'Position', [45+(i*51) 552-(j*50) 52 51],...
'Callback', @changeBG);
end
end
How can i get the correct button to pass to changeBG function? Can someone help me?
Thank you
0 comentarios
Respuesta aceptada
Orion
el 10 de Dic. de 2014
I'd say :
for i = 1 : 8
for j = 1 : 7
btn(j,i) = uicontrol('Parent', figure_handle, ...
'Style', 'pushbutton', ...
'Position', [45+(i*51) 552-(j*50) 52 51],...
'Callback', {@changeBG,i,j}); % add too arguments to changeBG
end
end
then in changeBG, something like
function changeBG(hobject,evendata,i,j)
if i==1 && j==1
set(hobject,'Backgroundcolor','r') % red for i=1, j=1
elseif ....
% same kind of treatment for each of your button
elseif ....
elseif ....
elseif ....
end
1 comentario
Más respuestas (1)
Daniel
el 10 de Dic. de 2014
If you mean the background as a whole and not just the color... I normally perform this task by modifying the "cdata" of that pushbutton. That allows you for example to use images as pushbutton background. Be careful by defining the size of the images so they fit properly inside the pushbutton you defined.
Hope it helps!
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!