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

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.

private void timer1_Tick(object sender, EventArgs e)
        {
            if (pictureBox1.Visible == true)
                pictureBox1.Visible = false;
            else
                pictureBox1.Visible = true;
        }

if you need more explanation please let me know.

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

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

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.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BlinkingImage
{
    public partial class Form1 : Form
    {
        /* form.size = 770,130 (770 is important since image will turn from a point close to that location,
         * in my case it turns from 677)
         * image will move between leftLocaton and write location. 
         */
        private int leftLocation = 12, rightLocation = 677;
        
        /* difference is used to move image to a directon. if difference is positive image will move to
         * right side, in contrast it will move to left side. if you give it a higher value, 
         * image will move faster.
         */
        private int difference = 2;
        
        public Form1()
        {
            InitializeComponent();
        }

        /* Timer1 makes image blink.
         */
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (pictureBox1.Visible == true)
                pictureBox1.Visible = false;
            else
                pictureBox1.Visible = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Interval = 300;
            timer2.Interval = 1;
            timer1.Start();
            timer2.Start();
        }

        /*Timer2 moves image left and write*/
        private void timer2_Tick(object sender, EventArgs e)
        {
            /*this statement changes the direction of the image, if it goes out of bounds.*/
            if ((pictureBox1.Left > rightLocation) || (pictureBox1.Left < leftLocation))
                difference *= -1;
            
            pictureBox1.Left += difference;
        }//timer2_Tick
    }//Form1
}//NameSpace

Thanks A lot Sir. It perfectly Worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.