Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Thread Subject:
active change of textbox color?

Subject: active change of textbox color?

From: Vihang Patil

Date: 25 Nov, 2007 07:03:26

Message: 1 of 1

Hello I am trying to achieve the following;
I have made a figure window with 5 uicontrols of textbox type
and assigned its background color property to "Red".
Now I want the background color property of these textboxes
to change depending upon the numeric value I enter.
For example,
If I press numeric 1 on my keyboard the First TextBox's
background Color should change to "Green". If I press
numeric 2 on my keyboard the second text box should turn
"Green". and so on and so forth.
I am able to achieve the basic requirement using the
following code I have attached.
But the problem is
1. I want the text box to change color only till the period
 I have pressed the respective numeric button. If I release
the button it should turn "Red" again
2. If I press two or three buttons simultaneously they
should change color accordingly.

My code currently does not change the color back to its
original red color once I have stopped pressing the key and
secondly I can only see one color change if I press two or
more keys.
Please guide


Attached Code......................

function tempgui
clear;close all, clc;
handles.h = figure;
handles.h1 = uicontrol('Style', 'text', 'String', '1',...
    'Position', [20 150 50 50],'BackgroundColor','red');
handles.h2 = uicontrol('Style', 'text', 'String', '2',...
    'Position', [100 150 50 50],'BackgroundColor','red');
handles.h3 = uicontrol('Style', 'text', 'String', '3',...
    'Position', [180 150 50 50],'BackgroundColor','red');
handles.h4 = uicontrol('Style', 'text', 'String', '4',...
    'Position', [260 150 50 50],'BackgroundColor','red');
handles.h5 = uicontrol('Style', 'text', 'String', '5',...
    'Position', [340 150 50 50],'BackgroundColor','red');

handles.tmr = timer('TimerFcn',


function TmrFCN(src,evnt,handles)
handles = guidata(handles);
val = get(handles.h,'CurrentCharacter');
if val == '1'
if val == '2'
if val == '3'
if val == '4'
if val == '5'

function closefig(src,evnt,handles)
handles = guidata(handles);
if strcmp

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us