Invalidate () method in C #

Source: Internet
Author: User
Control. invalidate Method

Invalidates a specific area of the Control and sends a draw message to the control.

Reload list

Invalidates a specific area of the Control and sends a draw message to the control.

Supported by the. NET Framework Lite version.

[C #] public void invalidate ();

[C ++] public: void invalidate ();

Invalidates a specific area of the Control and sends a draw message to the control. The sub-control assigned to the control is invalid.

[C #] public void invalidate (bool );

Make the specified area of the Control invalid (add it to the update area of the control, and re-draw the update area at the next draw operation), and send a draw message to the control.

Supported by the. NET Framework Lite version.

[C #] public void invalidate (rectangle );

Make the specified area of the Control invalid (add it to the update area of the control, and re-draw the update area at the next draw operation), and send a draw message to the control.

[C #] public void invalidate (region );

Make the specified area of the Control invalid (add it to the update area of the control, and re-draw the update area at the next draw operation), and send a draw message to the control. The sub-control assigned to the control is invalid.

[C #] public void invalidate (rectangle, bool );

Make the specified area of the Control invalid (add it to the update area of the control, and re-draw the update area at the next draw operation), and send a draw message to the control. The sub-control assigned to the control is invalid.

[C #] public void invalidate (Region, bool );

Example

[Visual Basic, C #, C ++] the following example enables you to drag an image or image file to a form and display it at a placement point. Every time you draw a form, override the onpaint method to re-draw the image; otherwise, the image will be redrawn until the next time. The dragenter event processing method determines the Data Type dragged to the form and provides appropriate feedback. If the image can be created from the data, the dragdrop event processing method will display the image on the form. Because the values of drageventargs. X and drageventargs. y are screen coordinates, the pointtoclient method is used in this example to convert them into workspace coordinates.

[C #]
Private image picture;
Private point picturelocation;

Public form1 ()
{
// Enable drag-and-drop operations and
// Add handlers for dragenter and dragdrop.
This. allowdrop = true;
This. dragdrop + = new drageventhandler (this. form1_dragdrop );
This. dragenter + = new drageventhandler (this. form1_dragenter );
}

Protected override void onpaint (painteventargs E)
{
// If there is an image and it has a location,
// Paint it when the form is repainted.
Base. onpaint (E );
If (this. Picture! = NULL & this. picturelocation! = Point. Empty)
{
E. Graphics. drawimage (this. Picture, this. picturelocation );
}
}

Private void form1_dragdrop (Object sender, drageventargs E)
{
// Handle filedrop data.
If (E. Data. getdatapresent (dataformats. filedrop ))
{
// Assign the file names to a string array, in
// Case the user has selected multiple files.
String [] files = (string []) E. Data. getdata (dataformats. filedrop );
Try
{
// Assign the first image to the picture variable.
This. Picture = image. fromfile (files [0]);
// Set the picture location equal to the drop point.
This. picturelocation = This. pointtoclient (new point (E. X, E. y ));
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
Return;
}
}

// Handle bitmap data.
If (E. Data. getdatapresent (dataformats. Bitmap ))
{
Try
{
// Create an image and assign it to the picture variable.
This. Picture = (image) E. Data. getdata (dataformats. Bitmap );
// Set the picture location equal to the drop point.
This. picturelocation = This. pointtoclient (new point (E. X, E. y ));
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
Return;
}
}
// Force the form to be redrawn with the image.
This. invalidate ();
}

Private void form1_dragenter (Object sender, drageventargs E)
{
// If the data is a file or a bitmap, display the copy cursor.
If (E. Data. getdatapresent (dataformats. Bitmap) |
E. Data. getdatapresent (dataformats. filedrop ))
{
E. effect = dragdropeffects. copy;
}
Else
{
E. effect = dragdropeffects. None;
}
}

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.