MFC 在Button控件上画线

在 Onpaint里画

void CLayoutDlg::OnPaint()

{

CPaintDC dc(this);

CButton* pButton = (CButton*)GetDlgItem(IDC_BUTTON_LAYOUT3);
ASSERT(pButton && pButton->GetSafeHwnd());
CDC* pdc = pButton->GetDC(); 获得控件DC

CPen pen;
pen.CreatePen(PS_SOLID, 1, RGB(0, 255, 0)); 绿笔
CPen* pOldpen = pdc->SelectObject(&pen);

//CRect rect;
//m_layoutBtn3.GetWindowRect(&rect);
//m_layoutBtn3.ScreenToClient(&rect);
//rect.OffsetRect(rect.left, rect.top);
pdc-> MoveTo(2, 20); 画一条横线,一条竖线
pdc-> LineTo(42, 20);
pdc-> MoveTo(22, 2);
pdc-> LineTo(22, 37);
//pdc-> LineTo(rect.left, rect.bottom);
//pdc-> LineTo(rect.left, rect.top);
pdc-> SelectObject(pOldpen);

ReleaseDC(pdc);

}

画线其实就是 获得 控件 DC ,然后 Moveto ,Lineto ,就行了


你可能感兴趣的:(MFC 在Button控件上画线)