Drawing of the form background (the Windows Form redraws its form background every time, so we can stop the form from redrawing the background message (WM_ERASEBKGND) and customize the method to achieve redrawing of the form background)

Source: Internet
Author: User

Core idea: Because Windows Forms redraws its form background every time, we can block the form from redrawing the background message (WM_ERASEBKGND), and customize the method to implement the redraw of the form background. The Timage component can also be implemented, but overriding the WM_ERASEBKGND message is more efficient, so it is recommended to use this method.

(2) Declaration Redraw background Message response function

void Fastcall Onwmerasebkgnd (twmerasebkgnd& Msg);


(3) Adding a message map

Begin_message_map
Intercept the redraw background event
Message_handler (WM_ERASEBKGND,TWMERASEBKGND,ONWMERASEBKGND);
End_message_map (Tform);


(4) code to write a custom background message response function

void Fastcall Tformmain::onwmerasebkgnd (twmerasebkgnd& Msg)
{
Re-painting background
tcanvas* canvas = new Tcanvas;
Canvas->handle = MSG.DC;
int cx = clientwidth/bmpformbk->width + 1;
int cy = clientheight/bmpformbk->height + 1;
for (int i=0; i<cy; i++)
for (int j=0; j<cx; j + +)
{
Canvas->draw (J*bmpformbk->width, I*BMPFORMBK->HEIGHT,BMPFORMBK); Msg.result = true;
}
Delete canvas;
}

Http://www.cnblogs.com/songsu/articles/1336653.html

Drawing of the form background (the Windows Form redraws its form background every time, so we can stop the form from redrawing the background message (WM_ERASEBKGND) and customize the method to achieve redrawing of the form background)

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.