Home All Groups Group Topic Archive Search About

Text box cannot change color at runtime

Author
29 May 2009 8:03 AM
hon123456
Dear all,

        I have to set text box color to gray. I use this code :

frmMain.txtDate.BackColor = &HC0C0C0

But the color of text box does not change at runtime. But when I set a
breakpoint at the above
code and run it, it does change color. What happened? I have delete
the text box control and
add a new textbox control. It still cannot change color when it runs.
Please help. Thanks.

Author
29 May 2009 8:29 AM
Clive Lumb
"hon123456" <peterhon***@yahoo.com.hk> a écrit dans le message de news:
cea2edc2-267b-4ba2-8a7d-93b834fed***@s28g2000vbp.googlegroups.com...
> Dear all,
>
>        I have to set text box color to gray. I use this code :
>
> frmMain.txtDate.BackColor = &HC0C0C0
>
> But the color of text box does not change at runtime. But when I set a
> breakpoint at the above
> code and run it, it does change color. What happened? I have delete
> the text box control and
> add a new textbox control. It still cannot change color when it runs.
> Please help. Thanks.

Does it change if you add a DOEVENTS after that line?
Author
29 May 2009 9:00 AM
Dave O.
"Clive Lumb" <clumb2@gratuit_en_anglais.fr.invalid> wrote in message
news:OGpaMeD4JHA.5204@TK2MSFTNGP02.phx.gbl...
>
> "hon123456" <peterhon***@yahoo.com.hk> a écrit dans le message de news:

> Does it change if you add a DOEVENTS after that line?
>
Or
frmMain.txtDate.Refresh
Which may be preferable to DoEvents as it won't let other things happen.

Dave O.
Author
29 May 2009 12:07 PM
Larry Serflaten
Show quote Hide quote
"hon123456" <peterhon***@yahoo.com.hk> wrote
> Dear all,
>
>         I have to set text box color to gray. I use this code :
>
> frmMain.txtDate.BackColor = &HC0C0C0
>
> But the color of text box does not change at runtime. But when I set a
> breakpoint at the above
> code and run it, it does change color. What happened? I have delete
> the text box control and
> add a new textbox control. It still cannot change color when it runs.
> Please help. Thanks.


It matters where you put that code, and what follows after executing that line of code.
For example if that code is in the Form_Unload event, you won't see a change.....

One thing you can do to watch for the change is to add a watch for it.  Right click
in the code window and select Add Watch...  then type in txtDate.BackColor and
select Break when value changes.

If it does change, the program will halt.  If it doesn't change, then you may have put
that code where it never gets to execute....

LFS