Label background transparency and text overlap problem solving method

Source: Internet
Author: User
When we use a non-system default color or picture in the window when the background, the above label and other controls are really affecting the beautiful


This issue, as long as the setting of the label background for Transparent can be resolved, the code is as follows:
C + + code?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 Hbrush Ctransparentctldlg::onctlcolor (cdc* PDC, cwnd* pWnd, UINT nctlcolor) {//Control background transparent processing begins----------------------- ------------------if (nctlcolor== ctlcolor_static)//If it is a static label {Pdc->setbkmode (TRANSPARENT) ; Set the background mode to transparent return (Hbrush) getstockobject (Null_brush); Returns an empty paint brush}//control background transparent processing end-----------------------------------------Hbrush HBR = Cdialog::onctlcolor      (PDC, PWnd, nCtlColor); return HBR; }



But then there is a problem, when we need to update the text above the label, will cause overlap, first look at the effect:
Setdlgitemtext (idc_static1,_t ("first text"));
Setdlgitemtext (idc_static1,_t ("second text"));


Workaround:Notifies the parent window to refresh after the text has been modified
C + + code?
1 2 3 4 5 6 7 8 9 10 11 12 13 void Ctransparentctldlg::onbnclickedbutton2 () {//2 times Modified label text Setdlgitemtext (idc_static1,_t ("first text"));      Setdlgitemtext (idc_static1,_t ("second text"));      Gets the rectangle position of the label CRect RC;      GetDlgItem (IDC_STATIC1)->getwindowrect (&RC);      Convert to relative coordinate screentoclient (&RC); Refreshes the specified area, noting that the 2nd parameter is true, that is, refreshing the background invalidaterect (&rc,true); }


Final Result:


SOURCE Download:
http://blog.csdn.net/cometnet/article/details/8706086

If you feel that the button above is not working well, refer to another post
Self-drawing realizes semi-transparent crystal button

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.