Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing focus on editbox? 1

Status
Not open for further replies.

mikeol

Programmer
Apr 22, 2003
8
IE
Is there any way to prevent an editbox from ever getting focus so that the user can never write to it?
I only want to use the box strictly to display text so the user can't be alowed write to it.

I did it before by keeping it disabled, and only enabling it when the program writes to it. But that turned the box grey, and changing the colour back to white seemed to crash it if I was writing to the box very quickly.
 
You can do this by intercepting EN_SETFOCUS and calling SetFocus() for another control ...

void MyDialog::OnSetfocusNoEntryItem()
{
GetDlgItem( IDC_ANOTHERITEM )->SetFocus();
}

An alternative would have been to use a text label rather than an edit box, though changing the value in the label needs slightly different techniques.

Best wishes,

tootired
 
Use ES_READONLY instead of WS_DISABLED
and make it a Rich Edit Control instead of an edit control

(it will behave the same as an edit control, except the background will be white when it is read-only.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top