Lm th? no ? thay ?i mu n?n c?a m?t Tab i?u khi?n

D?ch tiu ? D?ch tiu ?
ID c?a bi: 179909 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

Bi vi?t ny ch?ng t? lm th? no ? thay ?i mu n?n c?a m?i tab trong m?t i?u khi?n Tab. N gi? ?nh r?ng b?n c m?t h?p tho?i h?p v ? l?a ch?n v c kch th?c m?t Tab i?u khi?n vo h?p tho?i b?ng cch s? d?ng tr?nh so?n th?o ti nguyn.

THNG TIN THM

? thay ?i mu n?n c?a m?i tab, b?n ph?i th?c hi?n cc Tab control ch? s? h?u v? v s? d?ng cc phng php FillRect() ? i?n vo khu v?c h?nh ch? nh?t c?a cc tab ring c?a m?nh v?i m?t bn ch?i r?ng b?n t?o v g?i phng php SetBkColor() tr?c khi b?n th?c hi?n cu?c g?i phng php TextOut() v?i vn b?n b?n mu?n xu?t hi?n trn tab.

L?n ?u tin a ln cc thu?c tnh c?a tab i?u khi?n trong tr?nh so?n th?o ti nguyn v ch?n phong cch tab. ch?n cc "ch? s? h?u v? c? ?nh" h?p ki?m v ti?t ki?m cng vi?c c?a b?n. N?u b?n ang t? ?ng t?o cc Tab control trong cc kh?i t?o h?p tho?i v?i CreateWindow() ho?c CreateWindowEx() ch?c ch?n ? bao g?m TCS_OWNERDRAWFIXED cht trong tham s? dwStyle.

# Sau y xc ?nh ?c s? d?ng trong m?u:
        #define RED     RGB(255,0,0)
        #define YELLOW  RGB(255,255,0)
        #define MAGENTA RGB(255,0,255)
        #define WHITE   RGB(255,255,255)
        #define BLUE    RGB(0,0,255)
				

N?u b?n ang s? d?ng SDK

Bn ch?i trong o?n trch m?u ny ? ?c t?o ra trong WM_INITDIALOG v ang x? l? t?nh.

Thm tin nh?n WM_DRAWITEM ?n h?p tho?i th? t?c.

M?u m?

   case WM_DRAWITEM:
      lpdis = (LPDRAWITEMSTRUCT) lParam; // item drawing information
      hTabCtrl = GetDlgItem(hDlg, IDC_TAB1);

      if (hTabCtrl == lpdis->hwndItem)   // is this the tab control?
      {
         // which tab? first, second...fifth
         switch (lpdis->itemID)
         {
         case 0:
            hbr = hbrRed;
            bkColor = RED;
            break;
         case 1:
            hbr = hbrYellow;
            bkColor = YELLOW;
            break;
         case 2:
            hbr = hbrMagenta;
            bkColor = MAGENTA;
            break;
         case 3:
            hbr = hbrWhite;
            bkColor = WHITE;
            break;
         case 4:
            hbr = hbrBlue;
            bkColor = BLUE;
            break;
         }

         memset(szTabText, '\0', sizeof(szTabText));

         tci.mask = TCIF_TEXT;
         tci.pszText = szTabText;
         tci.cchTextMax = sizeof(szTabText)-1;

         TabCtrl_GetItem(hTabCtrl, lpdis->itemID, &tci);

         FillRect(lpdis->hDC, &lpdis->rcItem, hbr);
         SetBkColor(lpdis->hDC, bkColor);

         TextOut(lpdis->hDC,
               lpdis->rcItem.left,
               lpdis->rcItem.top,
               tci.pszText,
               lstrlen(tci.pszText));
      }
      break;
				

N?u b?n ang s? d?ng MFC

Bn ch?i ?c g?i l m?t ph?n c?a h?p tho?i l?p v ?c t?o ra khi cc nh xy d?ng h?p tho?i ?c g?i l.

Ghi phng php OnDrawItem() cho l?p CDialog b?t ngu?n c?a b?n b?ng cch s? d?ng l?p Thu?t s? v thm m? sau y, vi?c thay ?i tn bi?n nh c?n thi?t. i?u quan tr?ng c?n lu ? r?ng l m?t con tr? ?n m?t ?i t?ng CDC t? tay c?m c?a DC ?c thng qua trong thng qua LPDRAWITEMSTRUCT ?c yu c?u, n?u khng ch? cc n?n c?a cc vn b?n s? l mu mong mu?n.

M?u m?

       void CMFCTabCtrlDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpdis)
       {
          CDialog::OnDrawItem(nIDCtl, lpdis);

          char        szTabText[100];
          RECT        rect;
          UINT        bkColor;
          CBrush      *cbr;
          TC_ITEM     tci;

          CTabCtrl    *pTabCtrl = (CTabCtrl *)GetDlgItem(IDC_TAB1);

          if (pTabCtrl->m_hWnd == lpdis->hwndItem)
          {
              // which tab?
              switch (lpdis->itemID)
              {
              case 0:
                  cbr = &m_brRed;
                  bkColor = RED;
                  break;

              case 1:
                  cbr = &m_brYellow;
                  bkColor = YELLOW;
                  break;

              case 2:
                  cbr = &m_brMagenta;
                  bkColor = MAGENTA;
                  break;

              case 3:
                  cbr = &m_brWhite;
                  bkColor = WHITE;
                  break;

              case 4:
                  cbr = &m_brBlue;
                  bkColor = BLUE;
                  break;
              }

              memset(szTabText, '\0', sizeof(szTabText));

              tci.mask        = TCIF_TEXT;
              tci.pszText     = szTabText;
              tci.cchTextMax  = sizeof(szTabText)-1;

              pTabCtrl->GetItem(lpdis->itemID, &tci);

              CDC *dc = CDC::FromHandle(lpdis->hDC);

              dc->FillRect(&lpdis->rcItem, cbr);
              dc->SetBkColor(bkColor);

              TextOut(lpdis->hDC,
                      lpdis->rcItem.left,
                      lpdis->rcItem.top,
                      tci.pszText,
                      lstrlen(tci.pszText));
          }
       }
				

Thu?c tnh

ID c?a bi: 179909 - L?n xem xt sau cng: 20 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
T? kha:
kbctrl kbhowto kbtabctrl kbmt KB179909 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:179909

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com