Invalidate () method learning (data collection)

Source: Internet
Author: User

C # advanced programming: invalidate () method

  • Author: anonymous nameArticleSource: http://www.51shuji.com/Release Date:
  • Invalidate ()YesSystem. Windows. Forms. FormIt marks the client window area as invalid, so it can ensure thatPaintEvent.Invalidate ()There are two overload Methods: you can send a rectangle to it, specifying(Use Page coordinates)The window area to be re-drawn. If no parameter is provided, it marks the entire customer area as invalid.

    Why do you want to do this? If you know that some content needs to be drawn, why not callOnpaint ()Or other ways to directly complete the drawing task, generally, it is best not to directly call the drawing routine, ifCodeTo complete some drawing tasks, callInvalidate (). The reason is as follows:

     

    ● Drawing always GDI + ApplicationProgramA processor-intensive task that can be executed. Plotting in the middle of other jobs may impede other jobs. In the previous example LoadFile () A method is called directly in the method to complete the drawing, LoadFile () The method is returned only after the drawing is completed. During this period, the application will not respond to other events. On the other hand, by calling Invalidate () , In LoadFile Before returning, you can set Windows Trigger Paint Event. Next Windows You can check the events to be processed. The internal working mode is that an event is treated as a message in the message queue. Windows The queue is checked regularly. If there are events in the queue, WindowsSelect it and call the corresponding event handler. Now Paint An event is the only event in the queue, so Onpaint () Will be called immediately. However, in a complicated application, there may be other events, some of which have Priority Ratio Onpaint () High. Especially if the user has decided to exit the application, the event will use the message Wm_quit .

    ●Related to the first reason, if there is a complicated multi-threaded application, you will want to use a thread to process all the drawing operations. UseInvalidate ()All drawing operations can be passed to the information queue, which helps ensure that all drawing operations are performed by the same thread no matter what Drawing operation the other thread requests.(No matter what thread is responsible for the information queue, it is by the threadApplication. Run ()Process Drawing operations).

    ●There is another reason related to performance. Assuming that there are several different Screen Drawing requests at a time, the Code may only be able to modify the document to ensure that the updated document is displayed, and the user just removed another window that covers some customer regions. CallInvalidate ()To allowWindowsNote the event.WindowsMerge as neededPaintEvent, merge invalid areas, so that the drawing operation is only executed once.

    ●Finally, the code to execute the drawing may be the most complex part of the code in the application, especially when there is a professional user interface. People who need to maintain the code for a long time want us to put all the drawing code in one place and try to make it as simple as possible.-- If other parts of the program do not have too many paths to enter the code, maintenance is easier.

    The bottom line is that it is best to put all the drawing code inOnpaint ()Or other methods called in this method. But maintain a balance. If you want to replace a character on the screen, it is best not to affect other content that has been drawn.Invalidate ()Instead, you only need to write an independent drawing routine.

    Note:

    In very complex applications, you can even write a complete class specifically responsible for drawing on the screen. Years agoMFCStillGDIStandard Technology for intensive applications,MFCFollow this mode and useC ++ClassCviewComplete the Drawing operation. However, this class also has a member function.Ondraw ()Used as the entry point for most drawing requests.

  • From: http://www.tzwhx.com/newOperate/html/1/12/124/10475.html

    Invalidate () method in C #

    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); invalidates the specified area of the control (add it to the update area of the control, and re-draw the update area next time during the painting operation ), and send a draw message to the control.

    Supported by the. NET Framework Lite version.

    [C #] public void invalidate (rectangle); invalidates the specified area of the control (add it to the update area of the control, and re-draw the update area next time during the painting operation ), and send a draw message to the control.

    [C #] public void invalidate (region); invalidates the specified area of the control (add it to the update area of the control, and re-draw the update area next time during the painting operation ), and send a draw message to the control. The sub-control assigned to the control is invalid.

    [C #] public void invalidate (rectangle, bool); makes the specified area of the Control invalid (add it to the update area of the control, and re-draw the update area next time during the Painting 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.
    From: http://www.tzwhx.com/newOperate/html/1/12/122/16848.html

    msdn: The http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate (vs.71). aspx

    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.