Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Submit Assignment8a .cs file by including the .cs file in the zipped file with t

ID: 3535910 • Letter: S

Question

Submit Assignment8a .cs file by including the .cs file in the zipped file with the Assignment8b folder(s) noted below.

Notes: The requirements for this assignment are covered in the supporting material for this week. The assignment will require you to stretch your knowledge into some of the later chapters of the text and possibly some outside sources.

The form you are creating is run from a console application. You are creating a class for the form that inherits from System.Windows.Forms and because of this you can access and set all of the properties that the form has. The button objects also inherit from System.Windows.Forms and the button properties are all available to set/change. The two buttons also carry all of the button object methods such as Click, MouseOver etc. You need to write and implement the Click event method for each button.

All Windows Forms programs with their form and control objects act/change based on events. An event is an action on an object such as clicking a button. When a button is clicked, an event is registered by way of what is called a delegate (covered in a later chapter) and the event occurrence is passed to an event handler which implements an event method. Each button control has a _Click event method and since you are writing the code for the buttons you will write the event handlers for each button Click event. A click control event header has the general form: protected void <control name>_Click(Object sender, EventArgs e) where you would substitute the button name for <control name>. The event method takes an two arguments; a sender object and an EventArgs object that are automatically passed by the system. You don't have to pass any objects to the event method; the system does that for you. You just have to write the method header in the correct/expected format and then write the implementing code. The other thing you have to accomplish to make this work is toregister or attach each event handler to the named button.click event. This registering process fulfills the delegate requirements for each event. Don't worry right now about the delegate; assume that it is automatically in place. All you have to do is write code to register/attach each event handler to its corresponding button click.

I would write all of the code to implement requirements 1-8 and 12 without the event handlers first and once that works then add the event handling code. When you add the button controls to the form you can use one of two formats. You can do a Controls.Add() for each button or you can add both buttons at once using Controls.AddRange() as shown in the text.

Don't forget to add System.Drawing and System.Windows.Forms as references to your console project.

If you have any questions be sure to ask as early as possible (hint: start the project early in the week).

Here is a video of how Assignment8a and Assignment8b should look and work: assignment8.swf

[Assignment8b_yourlastname.cs] Create a Windows Forms Application project.


NOTE: When you submit Assignment8b that implements a Windows Form created using the Windows IDE you will need to provide the complete project folder for each project (not just the .cpp file). Please zip the entire project folder for submission to the DropBox. For an example see the zipped example file example8_2 at the top of the page.

Here are two videos that walk you through examples of how to build both a Windows Forms application and a form application that is generated from a console application.

Explanation / Answer

// Set the btnClickMe text to "Press Me" and the btnExit text to "Exit". this.btnClickMe.Text = "Press me"; this.btnExit.Text = "Exit"; // Add the two button controls to the form. this.Controls.AddRange(new Control[] { btnClickMe, btnExit }); // Set the btnClickMe location to coordinates 15, 20 this.btnClickMe.Location = new System.Drawing.Point(15, 20); // Register a new EventHandler for the Click event of the btnClickMe button this.btnClickMe.Click += new EventHandler(this.btnClickMe_Click); // "Click Me" in the MessageBox title bar when the Click event is fired. this.Text = "Click me"; // ...and the btnExit location to coordinates 15, 60. this.btnExit.Location = new System.Drawing.Point(15, 60); // ..new EventHandler for the Click event of the btnExit button. this.btnExit.Click += new EventHandler(btnExit_Click);