| | |
How to Blink an image
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
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.
if you need more explanation please let me know.
C# Syntax (Toggle Plain Text)
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:
Be Sure a.bmp exists in c colon
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 ;
} Last edited by selvaganapathy; Jun 14th, 2008 at 11:17 am.
KSG
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.
) it should move your image better but uses more of your CPU. anyway here is my code. C# Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- Raid-What it is and how it works (Storage)
- COntinous category List (RSS, Web Services and SOAP)
- Why do they make computers harder to use and program? (Geeks' Lounge)
- Can someone review my website (Website Reviews)
- Carets in turbo c++ 3.0 graphics? (C++)
- Aurora, DrPmon, MHTMLRedir problems (Viruses, Spyware and other Nasties)
- Norton Antivirus is FLASHING *blink* (Windows Software)
- The size of images change on different pcs (Site Layout and Usability)
Other Threads in the C# Forum
- Previous Thread: Reflection Invoke Method w/ Params
- Next Thread: adding wav file to program
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development display draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick mysql native networking operator path photoshop picturebox pixelinversion pixelminversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





