首页 > 代码库 > 自绘listCtrl控件选中该行高亮(模拟windows)
自绘listCtrl控件选中该行高亮(模拟windows)
CListCtrl的派生类CMyListCtrl的DrawItem()函数里添加代码
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); if (lpDrawItemStruct->itemState && LVIS_SELECTED) { CPen PenLine(PS_SOLID, 1, RGB(0, 0, 0)); CPen *OldPenLine = pDC->SelectObject(&PenLine); rcItem.right -= 2; rcItem.bottom -= 2; pDC->MoveTo(rcItem.left, rcItem.top); pDC->LineTo(rcItem.right, rcItem.top); pDC->MoveTo(rcItem.left, rcItem.top); pDC->LineTo(rcItem.left, rcItem.bottom); pDC->MoveTo(rcItem.left, rcItem.bottom); pDC->LineTo(rcItem.right, rcItem.bottom); pDC->MoveTo(rcItem.right, rcItem.top); pDC->LineTo(rcItem.right, rcItem.bottom); pDC->SelectObject(OldPenLine); rcItem.DeflateRect(2, 2, 2, 2); COLORREF m_color = RGB(71, 173, 255); for (int i = rcItem.Height() / 2; i>0; i--) { CPen pen(PS_SOLID, 1, m_color); CPen *OldPen = pDC->SelectObject(&pen); pDC->MoveTo(rcItem.left, rcItem.top + i); pDC->LineTo(rcItem.right, rcItem.top + i); pDC->MoveTo(rcItem.left, rcItem.bottom - i); pDC->LineTo(rcItem.right, rcItem.bottom - i); pDC->SelectObject(OldPen); } pDC->SetTextColor(RGB(255, 255, 255)); } else { pDC->SetTextColor(RGB(0, 0, 0)); CBrush brush; brush.CreateSolidBrush(RGB(255, 255, 255)); pDC->FillRect(rcItem, &brush); } CString strText = GetItemText(nRow, 0); CRect rcSubItem; GetSubItemRect(nRow, 0, LVIR_LABEL, rcSubItem); pDC->DrawText(strText, rcSubItem, DT_CENTER);
PenLine是在框内画线,模仿被选中的样子
图元的线型
PS_SOLID 实线
PS_DASH 虚线
PS_DOT 点线
PS_DASHDOT 点化线
PS_DASHDOTDOT 双点化线
自绘listCtrl控件选中该行高亮(模拟windows)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。