简体   繁体   中英

MFC edit box modify even

I want event on modifying MFCedit box, ie when I try to write or delete any letter.

I am getting the event on killing the focus but that's not required.

I want event while modifying the content of edit box.

To add to the existing answer(s), this can be done by adding the EN_CHANGE event handler for the control. This is a straightforward task using the IDE in Visual Studio.

There are a few approaches to this.


Method 1: Right-click the EDIT control and add an event handler:

上下文菜单

Click Add Event Handler... on the context menu and then locate the handler to add it:

添加处理程序

Make sure your dialog class is selected and that the EN_CHANGE message type is selected and then click OK to add the boiler plate code to your class. Now you can do what you need to do.


Method 2: Using the Properties Panel

属性面板

Make sure that the control is selected and that the Properties Panel is visible on screen.

  1. Click the Control Events (lightning icon) and you will see a list of events for the EDIT control.
  2. Locate EN_CHANGE and click the drop-down arrow.

You'll see a item to select there which will add the event handler for you.


Method 3: Using Class Wizard

Right-click the DIALOG resource ( not the EDIT control) and select Class Wizard...

上下文菜单

Then you can add the control using the Class Wizard:

类向导

To do this:

  1. Select the EDIT control ID on the list on the left.
  2. Select the EN_CHANGE event handler.
  3. Click the Add Handler... button.

As you can see, there are several ways to add the EN_CHANGE event handler.

Changes to the contents of an edit control are reported to clients through an EN_CHANGE notification. The CEdit documentation explains how to wire up class members to notification callbacks. In this case you'll want to add an ON_EN_CHANGE entry to your message map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM