Code for flashing images in winform

Source: Internet
Author: User

Enable a thread to process this function.

/// <Summary>

/// Flash the image in the specified image control
/// </Summary>
/// <Param name = "pic"> image control to be flashed </param>
Public static void flashimage (Object picbox)
{
Picturebox PIC = picbox as picturebox;
If (PIC = NULL)
Thread. currentthread. Abort ();

System. Windows. Forms. Control. checkforillegalcrossthreadcils = false;
// Cross-thread call. NET Framework 2.0 may cause this problem. You can run the specified delegate asynchronously on the thread where the basic handle of the control is created.

Bitmap BMP = new Bitmap (23, 23); // The size depends on the situation and does not affect other parts of the interface.
Graphics gph;
// Create a new graphics object from the specified image object
Color colortouming = color. fromargb (0,240,240,240); // transparent color
Gph = graphics. fromimage (BMP );
Bitmap mybit = new Bitmap (PIC. Image); // the picture of the picturebox control to be flashed
While (true)
{
Gph. Clear (colortouming );
Gph. drawimage (mybit, 0, 1, 20, 20 );
PIC. Image = BMP; // receives the message, and the picture beats
Thread. Sleep (300 );

Gph. Clear (colortouming );
Gph. drawimage (mybit, 1, 0, 23, 23 );
PIC. Image = BMP; // receives the message, and the picture beats
Thread. Sleep (300 );

Gph. Clear (colortouming );
Gph. drawimage (mybit, 1, 1, 20, 20 );
PIC. Image = BMP; // receives the message, and the picture beats
Thread. Sleep (300 );

Gph. Clear (colortouming );
Gph. drawimage (mybit, 1, 0, 23, 23 );
PIC. Image = BMP; // receives the message, and the picture beats
Thread. Sleep (300 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.