Looks to me that your code kinda works. I have tried it and it changes color. But it works when I remove MessageBox debug messages.
Advice DO NOT use MessageBox to display data as it interferes with what you are trying to debug, instead write to log file or console output.
It looks like you put them to debug, they caused all sorts of problems, you solved original problem but MessageBox problems remained.