How to Blink an image

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2007
Posts: 59
Reputation: Gaurav arora is an unknown quantity at this point 
Solved Threads: 0
Gaurav arora Gaurav arora is offline Offline
Junior Poster in Training

How to Blink an image

 
0
  #1
Jun 13th, 2008
hi there i have been working with C# for quite some time. I want to know How i will be able to insert an image in the form and get it blinked. Rather i have inserted the Image But i dont know how to blink it
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 48
Reputation: yilmazhuseyin is an unknown quantity at this point 
Solved Threads: 5
yilmazhuseyin's Avatar
yilmazhuseyin yilmazhuseyin is offline Offline
Light Poster

Re: How to Blink an image

 
0
  #2
Jun 14th, 2008
I'm sure there is a lot of way to do that but what I did was to put a timer (System.Windows.Forms in the components menu) on the form. and in its tick event write the following code.

  1. private void timer1_Tick(object sender, EventArgs e)
  2. {
  3. if (pictureBox1.Visible == true)
  4. pictureBox1.Visible = false;
  5. else
  6. pictureBox1.Visible = true;
  7. }

if you need more explanation please let me know.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: How to Blink an image

 
0
  #3
Jun 14th, 2008
Hi,
yilmazhuseyin was given good idea. My Suggestion, instead of changing the visible property of pictureBox, change the picture using timer.
For Ex:

    private bool change = true;
    private void timer1_Tick(object sender, EventArgs e)
    {
        if (change == true )
            pictureBox1.Image = Image.FromFile ("c:\\a.bmp");
        else
            pictureBox1.Image = null;
        change = !change ;
    }
Be Sure a.bmp exists in c colon
Last edited by selvaganapathy; Jun 14th, 2008 at 11:17 am.
KSG
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 59
Reputation: Gaurav arora is an unknown quantity at this point 
Solved Threads: 0
Gaurav arora Gaurav arora is offline Offline
Junior Poster in Training

Re: How to Blink an image

 
0
  #4
Jun 15th, 2008
thanks to all of u. It worked. but my objective was not only to blink the image but also to move it from left to right and right to left in the form. i have done it by changing the X property of location. But i m still unable to do it. Thanks for any suggestion
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 48
Reputation: yilmazhuseyin is an unknown quantity at this point 
Solved Threads: 5
yilmazhuseyin's Avatar
yilmazhuseyin yilmazhuseyin is offline Offline
Light Poster

Re: How to Blink an image

 
0
  #5
Jun 15th, 2008
if you do it in the same timer you will have a problem of having the image move very slowly, it is because image is blinking like every 3 seconds, but is should move like every milliseconds, so you have to use timer interval like 1 milliseconds and every 3 hundred times you gotta blink the image ones. and every time you have to move image. Or you can use two timers. while one of them blinks the image the other can move it right to left. this is a good way to do it. but timer class runs on the same thread with GUI so you might get kind of slowness, if you don't want that there is a multithreaded timer on System.Timers. you can use that too(I just saw it on MSDN now. ) it should move your image better but uses more of your CPU. anyway here is my code.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace BlinkingImage
  10. {
  11. public partial class Form1 : Form
  12. {
  13. /* form.size = 770,130 (770 is important since image will turn from a point close to that location,
  14.   * in my case it turns from 677)
  15.   * image will move between leftLocaton and write location.
  16.   */
  17. private int leftLocation = 12, rightLocation = 677;
  18.  
  19. /* difference is used to move image to a directon. if difference is positive image will move to
  20.   * right side, in contrast it will move to left side. if you give it a higher value,
  21.   * image will move faster.
  22.   */
  23. private int difference = 2;
  24.  
  25. public Form1()
  26. {
  27. InitializeComponent();
  28. }
  29.  
  30. /* Timer1 makes image blink.
  31.   */
  32. private void timer1_Tick(object sender, EventArgs e)
  33. {
  34. if (pictureBox1.Visible == true)
  35. pictureBox1.Visible = false;
  36. else
  37. pictureBox1.Visible = true;
  38. }
  39.  
  40. private void Form1_Load(object sender, EventArgs e)
  41. {
  42. timer1.Interval = 300;
  43. timer2.Interval = 1;
  44. timer1.Start();
  45. timer2.Start();
  46. }
  47.  
  48. /*Timer2 moves image left and write*/
  49. private void timer2_Tick(object sender, EventArgs e)
  50. {
  51. /*this statement changes the direction of the image, if it goes out of bounds.*/
  52. if ((pictureBox1.Left > rightLocation) || (pictureBox1.Left < leftLocation))
  53. difference *= -1;
  54.  
  55. pictureBox1.Left += difference;
  56. }//timer2_Tick
  57. }//Form1
  58. }//NameSpace
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 59
Reputation: Gaurav arora is an unknown quantity at this point 
Solved Threads: 0
Gaurav arora Gaurav arora is offline Offline
Junior Poster in Training

Re: How to Blink an image

 
0
  #6
Jun 20th, 2008
Thanks A lot Sir. It perfectly Worked.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC