Exposing events from a custom control
When you build any custom control, you need to expose additional events, based on the child controls and functionality that you want to expose to the user. In this recipe, we will learn how to expose a custom event from a custom control and perform a specific operation using it.
Getting ready
Let's start with the existing project that we have already used in the previous recipes. Launch the IDE and open the CH05.SearchControlDemo
project inside Visual Studio.
How to do it...
In this recipe, we will create a public event from the SearchControl
, so that we can subscribe to the PART_Button
button event and fetch the user-entered text. To do so, follow perform the following steps:
- From
Solution Explorer
, create a new class namedSearchEventArgs
, inside the project. - Extend the
SearchEventArgs
class from theEventArgs
and expose a public property (SearchTerm
) of typestring
. Here's the class implementation:
public class SearchEventArgs : EventArgs { public...