Changing Background Color of CEdit - Problem With Double Clicking On Texts 
Author Message
 Changing Background Color of CEdit - Problem With Double Clicking On Texts

Hi. I've a multiline edit control (IDC_EDIT1) which is
read-only. I tried to set the background color to white
and text color to blue using the default brush with the
following codes:

HBRUSH CCeditDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
nCtlColor)
{
        HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd,
nCtlColor);

        // TODO: Change any attributes of the DC here

        if (pWnd->GetDlgCtrlID() == IDC_EDIT1)
    {
                 CRect rc;
                 pWnd->GetClientRect(&rc);
                 pDC->Rectangle(0, 0, rc.Width(), rc.Height
());

                 pDC->SetBkColor(RGB(255, 255, 255));
                 pDC->SetTextColor(RGB(0, 0, 255));
    }

        // TODO: Return a different brush if the default
is not desired
        return hbr;

Quote:
}

Although this seems to work, every time I double click on
the texts inside the edit control, problem arises. The
selected texts get highlighted as expected but the rest of
the contents of the edit control simply disappear. Anybody
got any idea on how to fix this? Thanks.


Sun, 23 Oct 2005 10:52:39 GMT  
 Changing Background Color of CEdit - Problem With Double Clicking On Texts
I suspect your call to CDC::Rectangle which fills the interior of your
GetClientRect with the currently selected brush and frames it with the
currently selected pen. What happens if you take that out? Why is it
there in the first place?
--
Jeff Partch [VC++ MVP]


Quote:
> Hi. I've a multiline edit control (IDC_EDIT1) which is
> read-only. I tried to set the background color to white
> and text color to blue using the default brush with the
> following codes:

> HBRUSH CCeditDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
> nCtlColor)
> {
> HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd,
> nCtlColor);

> // TODO: Change any attributes of the DC here

> if (pWnd->GetDlgCtrlID() == IDC_EDIT1)
>     {
> CRect rc;
> pWnd->GetClientRect(&rc);
> pDC->Rectangle(0, 0, rc.Width(), rc.Height
> ());

> pDC->SetBkColor(RGB(255, 255, 255));
> pDC->SetTextColor(RGB(0, 0, 255));
>     }

> // TODO: Return a different brush if the default
> is not desired
> return hbr;
> }

> Although this seems to work, every time I double click on
> the texts inside the edit control, problem arises. The
> selected texts get highlighted as expected but the rest of
> the contents of the edit control simply disappear. Anybody
> got any idea on how to fix this? Thanks.



Sun, 23 Oct 2005 13:31:01 GMT  
 Changing Background Color of CEdit - Problem With Double Clicking On Texts
The call to CDC::Rectangle was meant to fill the entire
multiline edit control with the white background. If I
remove it, then the problem of disappering text is gone.
But then only the lines of the edit control which contain
texts are painted with the white background. The rest is
still in the default grey color... pls assist

Quote:
>-----Original Message-----
>I suspect your call to CDC::Rectangle which fills the
interior of your
>GetClientRect with the currently selected brush and
frames it with the
>currently selected pen. What happens if you take that
out? Why is it
>there in the first place?
>--
>Jeff Partch [VC++ MVP]



>> Hi. I've a multiline edit control (IDC_EDIT1) which is
>> read-only. I tried to set the background color to white
>> and text color to blue using the default brush with the
>> following codes:

>> HBRUSH CCeditDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
>> nCtlColor)
>> {
>> HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd,
>> nCtlColor);

>> // TODO: Change any attributes of the DC here

>> if (pWnd->GetDlgCtrlID() == IDC_EDIT1)
>>     {
>> CRect rc;
>> pWnd->GetClientRect(&rc);
>> pDC->Rectangle(0, 0, rc.Width(), rc.Height
>> ());

>> pDC->SetBkColor(RGB(255, 255, 255));
>> pDC->SetTextColor(RGB(0, 0, 255));
>>     }

>> // TODO: Return a different brush if the default
>> is not desired
>> return hbr;
>> }

>> Although this seems to work, every time I double click
on
>> the texts inside the edit control, problem arises. The
>> selected texts get highlighted as expected but the rest
of
>> the contents of the edit control simply disappear.
Anybody
>> got any idea on how to fix this? Thanks.

>.



Mon, 24 Oct 2005 02:30:51 GMT  
 Changing Background Color of CEdit - Problem With Double Clicking On Texts

Quote:
> The call to CDC::Rectangle was meant to fill the entire
> multiline edit control with the white background. If I
> remove it, then the problem of disappering text is gone.
> But then only the lines of the edit control which contain
> texts are painted with the white background. The rest is
> still in the default grey color... pls assist

You'll need to return an HBRUSH of the proper color. At a guess,
GetSysColorBrush(COLOR_WINDOW) is what you're after.

--
Jeff Partch [VC++ MVP]



Mon, 24 Oct 2005 02:44:13 GMT  
 Changing Background Color of CEdit - Problem With Double Clicking On Texts
Thanks Jeff. I've tried out GetSysColorBrush
(COLOR_WINDOW). But it seems that the entire window
(including the parent dialog) is painted with white
background. How can I paint only the entire edit control
without altering the color of the dialog?

Quote:
>-----Original Message-----


>> The call to CDC::Rectangle was meant to fill the entire
>> multiline edit control with the white background. If I
>> remove it, then the problem of disappering text is gone.
>> But then only the lines of the edit control which
contain
>> texts are painted with the white background. The rest is
>> still in the default grey color... pls assist

>You'll need to return an HBRUSH of the proper color. At a
guess,
>GetSysColorBrush(COLOR_WINDOW) is what you're after.

>--
>Jeff Partch [VC++ MVP]

>.



Mon, 24 Oct 2005 03:29:32 GMT  
 Changing Background Color of CEdit - Problem With Double Clicking On Texts
The text does not dissaper, but I guess since the
highlighted text have the same color as the highlighted
background, you can see them.

I don't know if there is control to set the 'highlighted'
color for edit control (what you did below was setting
color for normal (non-highlighted) text). You might want
to do your research there.

Quote:
>-----Original Message-----
>Hi. I've a multiline edit control (IDC_EDIT1) which is
>read-only. I tried to set the background color to white
>and text color to blue using the default brush with the
>following codes:

>HBRUSH CCeditDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
>nCtlColor)
>{
>    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd,
>nCtlColor);

>    // TODO: Change any attributes of the DC here

>    if (pWnd->GetDlgCtrlID() == IDC_EDIT1)
>    {
>             CRect rc;
>             pWnd->GetClientRect(&rc);
>             pDC->Rectangle(0, 0, rc.Width(), rc.Height
>());

>             pDC->SetBkColor(RGB(255, 255, 255));
>             pDC->SetTextColor(RGB(0, 0, 255));
>    }

>    // TODO: Return a different brush if the default
>is not desired
>    return hbr;
>}

>Although this seems to work, every time I double click on
>the texts inside the edit control, problem arises. The
>selected texts get highlighted as expected but the rest
of
>the contents of the edit control simply disappear.
Anybody
>got any idea on how to fix this? Thanks.

>.



Tue, 25 Oct 2005 18:10:43 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Change text color and background color in CEditView

2. Change a part of Background color or a part of text color from CListCtrl

3. Background & Text color CEdit

4. Setting text and background color in CEdit

5. Colored background and text in a CEdit control

6. How to change background color Of CEdit?

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

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

9. How to change background color of CEdit?

10. Change background color of disabled CEdit controls

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

12. Changing CEdit background COLOR on FOCUS????

 

 
Powered by phpBB® Forum Software