CEdit控件在OnPaint函数中,用CDC画了个矩形边框后(Rectangle)后,编辑框当鼠标移走时看不到刚刚输入的内容了,甚么原因?

解决方案 »

  1.   

    确定是边框,而不是一个实心的rect么?
      

  2.   

    派生CEdit,在OnPaint里:
    void MyEdit::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting
    CRect rect;
    GetWindowRect( &rect );
    CPen pen(PS_SOLID,2,RGB(255,0,0));
    CPen *old_pen = dc.SelectObject(&pen);int w = rect.Width() - 2 ;
    int h = rect.Height() - 2;
    dc.MoveTo(0,0);
    dc.LineTo(w,0);
    dc.LineTo(w,h);
    dc.LineTo(0,h);
    dc.LineTo(0,0);dc.SelectObject(old_pen);
    }
      

  3.   

    我这样画的:           CRect RectEditControl; GetClientRect (&RectEditControl); CDC *pEditControlDC; pEditControlDC = GetDC ();
    // do not remove
    // this algoritm is calculated client size with use or not horizontal
    // and vertical scroll bars
    RectEditControl.top    -= m_bHorizontalFrameWidth; RectEditControl.bottom += m_iHorizontalScrollWidth;
    RectEditControl.bottom += m_bHorizontalFrameWidth; RectEditControl.right  += m_iVerticalScrollWidthRight;
    RectEditControl.right  += m_bVerticalFrameWidth; RectEditControl.left   -= m_iVerticalScrollWidthLeft;
    RectEditControl.left   -= m_bVerticalFrameWidth;  CPen *OldPen = pEditControlDC->GetCurrentPen();
      CPen newPen(PS_SOLID, 1, RGB(255,0,0));
      pEditControlDC->SelectObject(&newPen);  // 画个边框
      pEditControlDC->Rectangle(RectEditControl.left, RectEditControl.top, 
          RectEditControl.right, RectEditControl.bottom);
      
      pEditControlDC->SelectObject(OldPen); // Release DC ! do not remove!
    ReleaseDC (pEditControlDC);
      

  4.   

    CDC::Rectangle  
    Draws a rectangle using the current pen. The interior of the rectangle is filled using the current brush.
    已经覆盖了EDIT文本框....
    你还是用我提供的画四条线的方法来解决