remove highlighting in a textarea

I have a multi-line, read-only text edit box.

When my dialog is initiallized, I place some text in the edit box, to display to the user.

The text always appears as marked highlighted - how can I un-highlight, or de-select the text inside the text area?

Thanks,

TimB
LVL 1
TimBAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
V_BapatConnect With a Mentor Commented:
I could simulate the problem.

Suppose you have 3 property pages. The 3rd page has the multiline edit control which is the only control on that page.

Case 1:
When the propertysheet opens, page is not the active page. Instead page 1 or 2 is active and another edit control(in my case) has the focus. Now if you click on page 3, all the text is highlighted.

Case 2:
When the propertysheet opens and page 3 is the active page.

Solution: Add a handler to EN_SETFOCUS and add m_edit.SetSel(-1,-1).

Sample Code:
BOOL CDummy::OnInitDialog()
{
      CPropertyPage::OnInitDialog();

      CString sLicence;
      sLicence = "COPYRIGHT/DISCLAIMER\r\nclientname\r\n";

      sLicence += "sdfl kfdlvk dfv dflkvjhfldkjv hfdlkjv\r\n hsfdlkjv slfdkjv hsfdlkvhvdalkjvh sdfkjvd\r\n";
      sLicence += "sdfl kfdlvk dfv dflkvjhfldkjv hfdlkjv\r\n hsfdlkjv slfdkjv hsfdlkvhvdalkjvh sdfkjvd\r\n";
      sLicence += "sdfl kfdlvk dfv dflkvjhfldkjv hfdlkjv\r\n hsfdlkjv slfdkjv hsfdlkvhvdalkjvh sdfkjvd\r\n";

      m_edit1.SetWindowText(sLicence);

      return TRUE;  // return TRUE unless you set the focus to a control
                    // EXCEPTION: OCX Property Pages should return FALSE
}

void CDummy::OnSetfocusEdit1()
{
      m_edit1.SetSel(-1, -1);
}

Vicky
0
 
V_BapatCommented:
m_edit.SetSel(-1, -1);

where m_edit is the member variable of the edit box.
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

Can u pls paste the code where u are inserting the text. But still try using SetSel(0,0,FALSE); for that edit control after inserting or after displaying.

Try it out.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
TimBAuthor Commented:
Hi,

I've tried both setsel(-1,-1), and setsel(0,0,false) - neather seemed to do the trick....

Here's my code:

BOOL CLiciencePage::OnInitDialog()
{
 CPropertyPage::OnInitDialog();
      
 CString sLicience;
 sLicience = "COPYRIGHT/DISCLAIMER\r\clientname\r\n";
 
 sLicience += (about 300 words of text)

 m_LICIENCE_EDIT.SetWindowText(sLicience);
 m_LICIENCE_EDIT.SetSel(0,0,FALSE);



 return TRUE;  // return TRUE unless you set the focus to a control
 // EXCEPTION: OCX Property Pages should return FALSE
}

//////////////

looking at this - is this something to do with returning TRUE (as its a proberty page)?

TimB
0
 
V_BapatCommented:
Maybe that edit control has focus. Try to set focus to any other control.
0
 
TimBAuthor Commented:
the textarea is the only component I've placed in this propertypage....
0
 
V_BapatCommented:
Then I would suggest you to use CStatic control and set text the same you are doing.
0
 
TimBAuthor Commented:
Ok, I might do that....

If you don''t mind, I'll reject your initial answer - just in case someone else can help.

If I use a cstatic in the end can you resubmit...


Thanks,

TimB
0
 
V_BapatCommented:
You can also try to add a dummy control, make it invisible and set focus to that control.
0
 
pagladasuCommented:
It appears that SetSel() does not work when written in OnInitDialog() function. Move the code to OnShowWindow() (use classwizard to map WM_SHOWWINDOW) and you will find it working.

Here is what I did:
void CEditcDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
      CDialog::OnShowWindow(bShow, nStatus);
      m_edit.SetSel(-1,0);
      // TODO: Add your message handler code here
      
}
0
 
TimBAuthor Commented:
Nope,

That didn't work...

I'm using property pages instead of dialogs, but I don't see how that would make a difference.

0
 
bhatCommented:
Hi ,

It is not required to do that much as Vbapat has said.

Just change the tab order in the resource editor. The edit box may be having the tab order as 1. Change it to 2 .
and set the other control as 1.

Hope this helps
0
 
TimBAuthor Commented:
Fantastic!

That worked a treat...

Thanks,

Tim
0
All Courses

From novice to tech pro — start learning today.