VC modifies the background color, font color, and usage of ListBox in the list box.

Source: Internet
Author: User

I. Modify the background color and font color
① Create a project based on the dialog box, name it test, and add a ListBox control to the dialog box.
② Add a member variable in testdlg. h: hbrush m_hbrush;
③ In oninitdialog (), add m_hbrush = createsolidbrush (RGB (, 0). The RGB value set here can change the background color of ListBox. To view the color changes of the words in the ListBox, add a few words to the ListBox: Use the Class Wizard to add a control type member variable m_ctrllistbox To The ListBox, and then add the following to oninitdialog ():Code:
M_ctrllistbox.addstring ("first line ");
M_ctrllistbox.addstring ("second row ");
④ Click Class Wizard, add the wm_ctlcolor event to testdlg, click the edit code button, and replace the content of the function with the following code:
If (nctlcolor = ctlcolor_listbox)
{
PDC-> setbkmode (transparent );
// Set the font color here
PDC-> settextcolor (RGB (255,255,255 ));
Return m_hbrush;
}
Else
Return cdialog: onctlcolor (PDC, pwnd, nctlcolor );
Compile and run change nowProgram, You can see that the list box has become black and the word has become white!
1. Add dataM_listbox.addstring ("fadsfasdfsdaf ");
2. Calculate the number of data entriesM_listbox.getcount ();
3. Clear the list boxM_listbox.resetcontent ();

Http://blog.csdn.net/halibobo520/article/details/3372099

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.