473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to change color of form after every 3 sec. in vc#

i want to change color of form after every 3 sec. in vc#. How it can be done with the help of timer. Do i need to use a loop if yes then how?

Thanx
Sep 15 '10 #1
9 2202
Frinavale
9,735 Expert Mod 8TB
Add a Timer control to the form and implement code that handles time Timer's Tick event. In that method set the Window.Form.BackColor property.

-Frinny
Sep 15 '10 #2
I have already tried this but can u suggest me something else my code is
Expand|Select|Wrap|Line Numbers
  1.  private void timer1_Tick(object sender, EventArgs e)
  2.  {
  3.    this.BackColor = Color.Red;
  4.  }
Plz. help me out

Thankx
Sep 15 '10 #3
Frinavale
9,735 Expert Mod 8TB
Try calling the Update method afterwords to force the control to refresh.
Sep 15 '10 #4
Plater
7,872 Expert 4TB
That code always sets the background to red. Then what?
Sep 15 '10 #5
Use an IF...ELSE condition in timer_tick event to set different colors depending upon value property of timer control.
Sep 16 '10 #6
hi
thankx for ur suggestions. Somebody suggested me to use random class/method. but i dont know how to use here. plz. guide.
Sep 18 '10 #7
you can use random class as:

Expand|Select|Wrap|Line Numbers
  1. Random rndObj = new Random();           
  2. if(rndObj.Next(1, 4).ToString()== "1")
  3. {
  4. this.BackColor = Color.Red;
  5. }
  6. else
  7. if(rndObj.Next(1, 4).ToString()== "2")
  8. {
  9. this.BackColor = Color.Green;
  10. }
  11. else
  12. if(rndObj.Next(1, 4).ToString()== "3")
  13. {
  14. this.BackColor = Color.Yellow;
  15. }
  16. else
  17. {
  18. this.BackColor = Color.White;
  19. }
Sep 19 '10 #8
Thanks, but i want to change the color with timer.
Sep 20 '10 #9
just put a timer on the form and set its interval to 1000 that is, representing milliseconds....

play Button:
Expand|Select|Wrap|Line Numbers
  1. Timer1.start();
Now on ur .cs file...

Expand|Select|Wrap|Line Numbers
  1. public int a=10; 
then on the timer's tick event.put the following code
Expand|Select|Wrap|Line Numbers
  1. a--;
  2. if(a==10)
  3.   this.backcolor= color.red;
  4.  
  5. else if(a==9)
  6.   this.backcolor= color.blue;
and so on....
Oct 5 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: vikas2923 | last post by:
Can any body tell me plz how to change color on deactivating a text box i had tried the code but every time it is giving an error message "object not defined" .Pleased provide me the cod of it or...
2
by: nitindutt2005 | last post by:
Hi I have a html file as below. ==================================================================== <html> <head> <td style="background-color:rgb(170, 157, 244);"> <table border="0"...
1
by: itsenthil | last post by:
This is my Usercontrolcoding. what is wrong in this coding plz help me <script type="text/javascript" language="javascript"> function output() { var cb...
2
by: ksingh | last post by:
I have a form with a sub form and I want the field on the main form to change color if the date is greater than today. The field on the main form changes when I scroll from one record to another. ...
1
by: dotcom | last post by:
hello friends, in my form my div has both scrolling (horizontal as well as vertical) but for horizontal scrollbar i want to change color plz help me if anybody know the solution
5
by: abhubbart | last post by:
I want change the color on the font to red for the text within the div element. I have the following code. <style type="text/css"> .style2 {color: #000000} </style>
2
by: cloh | last post by:
Hi all, Does anyone know if it is possible to change the color of a radio button in a form? Changing either the color of the border or the dot would work for me - I just need it to stand out from...
10
by: The Bicycling Guitarist | last post by:
Hello. I have a navigation bar at the top of all my pages with css-styled buttons that change color when hovered over. I am a little confused on how to disable that for the link that the page is...
3
by: viki1967 | last post by:
Hi all. This code javascript not working... nothing error but not working... :( I need change color in the fields of the form when fields is null... My code:
1
by: Anwesha | last post by:
Hi, i have a problem while working with .net 2005. i have a situation where i have to change the form id which takes 'form1' by default. it donot allow me to change the id form the property...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.