Add background to the MDI parent form and solve the problem of blinking

Source: Internet
Author: User

# Region adds background to the MDI parent form and solves the problem of blinking
// 1. Add a background image named "backgroundimage" to properties/resources. resx.

 

// 2. Add backgroundnosplash () in the following locations ();

Public frmmain ()
{

Initializecomponent ();

// Add background to the MDI parent form and solve the problem of blinking
Backgroundnosplash ();

}

 

// The followingCodeCopy to the MDI main form code

Mdiclient = new mdiclient ();

Private void backgroundnosplash ()
{
Foreach (control VaR in this. Controls)
{
If (VaR is mdiclient)
{
Mdiclient = VaR as mdiclient;
Break;
}
}

If (mdiclient! = NULL)
{< br> mdiclient. paint + = new painteventhandler (onmdiclientpaint);
system. reflection. methodinfo MI = (mdiclient as control ). getType (). getmethod ("setstyle", system. reflection. bindingflags. nonpublic | system. reflection. bindingflags. instance);
mi. invoke (mdiclient, new object [] {controlstyles. allpaintinginwmpaint | controlstyles. userpaint | controlstyles. optimizeddoublebuffer
| controlstyles. resizeredraw, true});

}< BR >}

Private void onmdiclientpaint (Object sender, painteventargs E)
{
Graphics G = E. graphics;
G. drawimage (properties. Resources. backgroundimage, new rectangle (0, 0, mdiclient. Width, mdiclient. Height ));
String MSG = "system name + version number + last update date ";
Sizef size = E. Graphics. measurestring (MSG, this. font );
G. drawstring (MSG, this. Font, new solidbrush (color. White), mdiclient. Width-size. Width, mdiclient. Height-size. Height );

}

# endregion

Related Article

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.