Published · 1 min read

Event Driven Programming

Prior to the Event Driven model, programming was procedural, where there would be an entry point for the application, typically known as the main function.

Prior to the Event Driven model, programming was procedural, where there would be an entry point for the application, typically known as the main function. From there, the flow of execution could be branched to different modules depending upon conditions such as inputs from the user. In an Event Driven Paradigm, the execution is not necessarily continuous. The statements that will be executed depend on the events. The events could be user generated: Clicking a Button, Closing a Window, Moving the mouse over a contol and so on, or system generated such as elapsing of a timer’s interval.

We write codes corresponding to these events which are executed when ever the event takes place. For example, the following code shows a dialog box with the message “Hello World” when the Show button is clicked:-

private void ShowMessage_Click(object sender, EventArgs e)
{
	MessageBox.Show("Hello World");
}

Notice the words object sender, EventArgs e, these are the parameters being passed along with the event. These parameters are used to determine the state of the control. In the following example, the KeyPressEventArgs being passed along with the event, is used to determine the key that was pressed in a text box.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
	MessageBox.Show(e.KeyChar.ToString());
}
Partho Sarathi

Partho Sarathi

Founder, Maxotek

Programming Basics

Our blog

Related posts

Tutorials, notes and news from Maxotek.

  • Digital logic gates

    Digital logic gates is an electronic component which results perticular ouput after implementing its logic on the input signals.

    Partho Sarathi

    Partho Sarathi

  • 64-Bit Computing

    Around 2003 the term 64-Bit computing was everywhere. Want to install Windows XP? Great! Do you want the 32-Bit disc or 64-Bit disc? Installing WinZip for your shiny new re-installed OS?

    Partho Sarathi

    Partho Sarathi

View all posts

See what Maxotek makes

Monitoring, conversion tools and more, built by the same people who wrote these posts.