Tag Archives: event handlers

Make a class define and raise events in C#

This example uses a BankAccount class to manage a bank account (and to show how to define and raise events). If the program tries to remove more money from the account than its current balance, the BankAccount object raises an … Continue reading

Posted in classes, events | Tagged , , , , , , , , , , , , | 4 Comments

Make a standard color palette in C#

The MakeColorPalette method shown below builds an array of PictureBoxes with BackColor properties set to a standard color palette. // Make a color palette on the given parent. private void MakeColorPalette(Control parent, int x, int y, System.EventHandler event_handler) { Color[] … Continue reading

Posted in controls, drawing, graphics | Tagged , , , , , , , , , , , | 1 Comment

Let controls share event handlers in C#

Sometimes it would be useful to let controls share event handlers. Often a program has several controls that do almost the same thing. It would be nice if they could share the same event handler to increase code reuse, but … Continue reading

Posted in controls, methods | Tagged , , , , , , , , , , , , | Leave a comment

Use an event handler for multiple controls in C#

Suppose you have several controls with event handlers that perform similar complex tasks. There are two general approaches for minimizing duplicated code. The first is to move the common code into a separate method and make all of the event … Continue reading

Posted in controls, Event | Tagged , , , , , , , | 2 Comments