Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Adding Event Handlers for Dialog Box Controls

For project dialog boxes that are already associated with a class, you can take advantage of some shortcuts when you create event handlers. You can quickly create a handler either for the default control notification event or for any applicable Windows message.

To create a handler for the default control notification event

  1. Double-click the control. The Text editor opens.

  2. Add control notification handler code in the Text editor.

To create a handler for any applicable Windows message

  1. Click the control for which you want to handle the notification event.

  2. In the Properties window, click the ControlEvents button to display the list of common Windows events associated with the control. For example, the standard OK button on the About dialog box lists the following notification events:

    BN_CLICKED

    BN_DOUBLECLICKED

    BN_KILLFOCUS

    BN_SETFOCUS

    NoteNote:

    Alternately, select the dialog box and click the ControlEvents button to display the list of common Windows events for all controls in the dialog box.

  3. In the Properties window, click the right column next to the event to handle, and then select the suggested notification event name (for example, OnBnClickedOK handles BN_CLICKED).

    NoteNote:

    Alternately, you can provide an event handler name of your choice, rather than selecting the default event handler name.

    Once you have selected the event, Visual Studio opens the Text Editor and displays the event handler's code. For example, the following code is added for the default OnBnClickedOK:

    void CAboutDlg::OnBnClickedOk(void)
    {
       // TODO: Add your control notification handler code here
    }
    

If you want to add the event handler to a class other than the one implementing the dialog box, use the Event Handler wizard. For more information, see Adding an Event Handler.

For information on adding resources to managed projects, please see Resources in Applications in the .NET Framework Developer's Guide. For information on manually adding resource files to managed projects, accessing resources, displaying static resources, and assigning resources strings to properties, see Walkthrough: Localizing Windows Forms and Walkthrough: Using Resources for Localization with ASP.NET.

Requirements

Win32

Community Additions

ADD
Show:
© 2015 Microsoft