Changing CEdit background COLOR on FOCUS???? 
Author Message
 Changing CEdit background COLOR on FOCUS????

I am using a CFormView and have overridden OnCtlColor. I want all my edit
boxes to change their background color on focus:

I have done the following

OnCtlColor(CWnd * pWnd, CDC pDC, int flag)
{

    if (pWnd == GetFocus()
    {
        pDC->SetBkColor(RGB(255,255,0));
        return m_hYellowBrush;
    }
    else
    {
           return  CFormView::OnCtlColor(pWnd, pDC, flag);
    }

Quote:
}

The problem is, it does not color the whole back ground. It only colors the
background behind the text, so
it leaves a white border around the edge of the control.

If I replace pWnd == GetFocus() with pWnd == (CWnd *) &m_myEditCtrl it
works......

Am I being stupid...please help.

Matthew Barrett.

Matthew.



Mon, 10 Sep 2001 03:00:00 GMT  
 Changing CEdit background COLOR on FOCUS????
Matthew:

I'm not sure if this is your problem, but it is generally not a good idea to
compare CWnd pointers. Do

if (pWnd->m_hWnd == ::GetFocus())

But what you say sounds strange. You mean that as you change the focus among
the edit controls, the text background color changes (so your code must be
getting called for both edits) but that the rest of the background does not
change?

Of couse another way to do this is to use derived CEdit and handle WM_SETFOCUS
and WM_KILLFOCUS.

HTH,

David Wilkinson

============

Quote:

> I am using a CFormView and have overridden OnCtlColor. I want all my edit
> boxes to change their background color on focus:

> I have done the following

> OnCtlColor(CWnd * pWnd, CDC pDC, int flag)
> {

>     if (pWnd == GetFocus()
>     {
>         pDC->SetBkColor(RGB(255,255,0));
>         return m_hYellowBrush;
>     }
>     else
>     {
>            return  CFormView::OnCtlColor(pWnd, pDC, flag);
>     }
> }

> The problem is, it does not color the whole back ground. It only colors the
> background behind the text, so
> it leaves a white border around the edge of the control.

> If I replace pWnd == GetFocus() with pWnd == (CWnd *) &m_myEditCtrl it
> works......

> Am I being stupid...please help.

> Matthew Barrett.

> Matthew.



Mon, 10 Sep 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Changing Background Color of CEdit - Problem With Double Clicking On Texts

2. How to change background color Of CEdit?

3. Changing the default background color of disabled control (CEdit)

4. How to change background color of a dynamically created CEdit control

5. How to change background color of CEdit?

6. Change background color of disabled CEdit controls

7. Changing the Background Color of Individual CEdit controls in a CDialogBar

8. Change background color of CEdit in CEditView

9. change the CEdit Background color - but tricky!

10. Changing color of background of a CEdit control

11. How to change CEdit window background color without derivation from it a new class

12. Changing the Background Color of a Dialog to match the background of a Bitmap

 

 
Powered by phpBB® Forum Software