How to Use strings that cannot be displayed. Replace

Source: Internet
Author: User
Tags textout

There are many rect records on the progress bar. Each rect shows an operation name. When the name is too long to display all records, you need to process the string. My method is to directly display the string in the middle of the rect when the length of the string is smaller than the width of the rect. When the value is greater than the rect width, the rect width must be used as the reference. Specific implementation of C ++CodeAs follows:

 

csize size = dc. gettextextent (STR);
If (size. CX <= m_parrrects [I]. height () // when rect. weigth <= Currently rect. height, direct showing;
{< br> DC. textout (m_parrrects [I]. centerpoint (). X + size. cy/2, m_parrrects [I]. centerpoint (). y-size.cx/2, STR);
}< br> else // when rect. weigth> currently rect. height, delete the end character to adapt the rect
{< br> int strlength = (m_parrrects [I]. height ()-40)/10;
If (strlength % 2 = 1) // use for Jap, and Chinese
{< br> strlength = strlength + 1;
}< br> cstring stradd = "... ";
cstring strshort;
strshort = Str. left (strlength);
strshort + = stradd;
DC. textout (m_parrrects [I]. centerpoint (). X + size. cy/2, m_parrrects [I]. top, strshort);
}

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.