User:Foxall/18

Ka Wiktionary

Hour 18. Interacting with Users[wax ka badal]

Forms and controls are the primary means by which users interact with an application, and vice versa. However, program interaction can and often does go deeper than that. For example, a program can display customized messages to a user, and it can be finely tuned to deal with certain keystrokes or mouse clicks. In this hour, you'll learn how to create functional and cohesive interaction between your application and the user. In addition, you'll learn how to program the keyboard and the mouse so that you can expand the interactiveness of your program beyond what is natively supported by a form and its controls.

The highlights of this hour include the following:

  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch18lev1sec1.htm#ch18lev1sec1 Displaying messages using the MessageBox.Show() method]
  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch18lev1sec2.htm#ch18lev1sec2 Creating custom dialog boxes]
  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch18lev1sec3.htm#ch18lev1sec3 Interacting with the keyboard]
  • [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch18lev1sec4.htm#ch18lev1sec4 Using the common mouse events]

>

Displaying Messages Using the MessageBox.Show() Method

A message box is a small dialog box that displays a message to the user. Message boxes are often used to tell the user the result of some action, such as The file has been copied. or The file could not be found. A message box is dismissed when the user clicks one of the message box's available buttons. Most applications have many message boxes, yet developers often don't display messages correctly. It's important to remember that when you display a message to a user, you're communicating with the user. In this section, I want to teach you not only how to use the MessageBox.Show() method to display messages, but how to use the statement effectively.

The MessageBox.Show() method can be used to tell a user something or ask the user a question. In addition to text, which is its primary function, you can also use this function to display an icon or display one or more buttons that the user can click. Although you are free to display whatever text you want, you must choose from a predefined list of icons and buttons.

A MessageBox.Show() method is an overloaded method. This means that the method was written with numerous constructs supporting various options. While coding in Visual Studio .NET, IntelliSense displays a drop-down scrolling list displaying any of the twelve overloaded MessageBox.Show method calls to aid in coding. Following are a few ways to call MessageBox.Show():

To display a message box with specified text, a caption in the title bar, and an OK button, use this syntax:

MessageBox.Show(MessageText, Caption);

To display a message box with specified text, caption, and one or more specific buttons, use this syntax:

MessageBox.Show(MessageText, Caption, Buttons);

To display a message box with specified text, caption, buttons, and icon, use this syntax:

MessageBox.Show(MessageText, Caption, Buttons, Icon);

In all these statements, MessageText is the text to display in the message box, Caption determines what appears in the title bar, Buttons determines which buttons the user sees, and Icon determines what icon (if any) appears in the message box. Consider the following statement, which produces the message box shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig01 Figure 18.1].

MessageBox.Show("This is a message.");

As you can see, if you omit Buttons, C# displays only an OK button. You should always ensure that the buttons displayed are appropriate for the message.

graphics/bookpencil.gif The Visual Basic MsgBox() function defaults the caption for the message box to the name of the project. There is no default in C#.
Specifying Buttons and an Icon 

The Buttons parameter contains the "meat" of the message box statement. Using the Buttons parameter, you can display a button (or buttons) in the message box. The Buttons parameter type is MessageBoxButtons, and the allowable values are shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18table01 Table 18.1].

Members Description
AbortRetryIgnore Displays Abort, Retry, and Ignore buttons.
OK Displays OK button only.
OKCancel Displays OK and Cancel buttons.
YesNoCancel Displays Yes, No, and Cancel buttons.
YesNo Displays Yes and No buttons.
RetryCancel Displays Retry and Cancel buttons.

Because the Buttons parameter is an enumerated type, C# gives you an IntelliSense drop-down list when specifying a value for this parameter. Therefore, committing these values to memory isn't all that important; you'll fairly quickly commit the ones you use most often to memory.

The Icon parameter determines the symbol displayed in the message box. The Icon parameter is an enumeration from the MessageBoxIcon type. The MessageBoxIcon has the values shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18table02 Table 18.2].

Members Description
Asterisk Displays a symbol consisting of a lowercase letter i in a circle.
Error Displays a symbol consisting of a white X in a circle with a red background.
Exclamation Displays a symbol consisting of an exclamation point in a triangle with a yellow background.
Hand Displays a symbol consisting of a white X in a circle with a red background.
Information Displays a symbol consisting of a lowercase letter i in a circle.
None Displays no symbol.
Question Displays a symbol consisting of a question mark in a circle.
Stop Displays a symbol consisting of a white X in a circle with a red background.
Warning Displays a symbol consisting of an exclamation point in a triangle with a yellow background.

The Icon parameter is also an enumerated type; therefore, C# gives you an IntelliSense drop-down list when specifying a value for this parameter.

The message box in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig02 Figure 18.2] was created with the following statement:

MessageBox.Show("I'm about to do something...","MessageBox sample",
 MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
Figure 18.2. Assign the Information icon to general messages.

graphics/18fig02.jpg

The message box in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig03 Figure 18.3] was created with a statement almost identical to the previous one, except that the second button is designated the default button. If a user presses the Enter key with a message box displayed, the message box acts as though the user clicked the default button. You'll want to give careful consideration to the default button in each message box. For example, if the application is about to do something that the user probably doesn't want to do, it's best to make the Cancel button the default button�in case the user is a bit quick when pressing the Enter key. Following is the statement used to generate the message box in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig03 Figure 18.3].

Figure 18.3. The default button has a dark border.

graphics/18fig03.jpg

MessageBox.Show("I'm about to do something...","MessageBox sample",
 MessageBoxButtons.OKCancel,MessageBoxIcon.Information,
 MessageBoxDefaultButton.Button2);

In [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig04 Figure 18.4], the Error icon is shown. The Error icon is best used in rare circumstances, such as when an exception has occurred. Overusing the Error icon is like crying wolf�when a real problem emerges, the user might not take notice. Notice here how I've displayed only the OK button. If something has already happened and there's nothing the user can do about it, don't bother giving the user a Cancel button. The following statement generated the message box shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig04 Figure 18.4].

Figure 18.4. If users have no control over what has occurred, don't give them a Cancel button.

graphics/18fig04.jpg

MessageBox.Show("Something bad has happened!","MessageBox sample",
 MessageBoxButtons.OK,MessageBoxIcon.Error);

In [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig05 Figure 18.5], a question has been posed to the user, so I chose to display the Question icon. Also note how I assumed that the user would probably choose No, so I made the second button the default. In the next section, you'll learn how to determine which button the user clicks. Here's the statement used to generate the message box shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig05 Figure 18.5]:

MessageBox.Show("Would you like to format your hard drive now?",
 "MessageBox sample",MessageBoxButtons.YesNo,MessageBoxIcon.Question,
 MessageBoxDefaultButton.Button2);
Figure 18.5. Message boxes can be used to ask a question.

graphics/18fig05.jpg

As you can see, designating buttons and icons is not all that difficult. The real thought comes in determining which buttons and icons are appropriate for a given situation.

 Determining Which Button Is Clicked 

You'll probably find that many of your message boxes are simple, containing only an OK button. For other message boxes, however, you'll need to determine which button a user clicks. Why give the user a choice if you're not going to act on that choice? The MessageBox.Show() method returns the button clicked as a DialogResult enumeration. The DialogResult has the following values, as shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18table03 Table 18.3].

Members Description
Abort Return value Abort, usually sent from a button labeled Abort.
Cancel Return value Cancel, usually sent from a button labeled Cancel.
Ignore Return value Ignore, usually sent from a button labeled Ignore.
No Return value No, usually sent from a button labeled No.
None Nothing is returned from the dialog box. The model dialog will continue running.
OK Return value OK, usually sent from a button labeled OK.
Retry Return value Retry, usually sent from a button labeled Retry.
Yes Return value Yes, usually sent from a button labeled Yes.

Performing actions based on the button clicked is a matter of using one of the decision constructs. For example:

if (MessageBox.Show("Would you like to do X?","MessageBox sample",
 MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
 // Code to do X would go here.

As you can see, MessageBox.Show() is a method that gives you a lot of "bang for your buck"; it offers considerable flexibility.

 Crafting Good Messages 

The MessageBox.Show() method is surprisingly simple to use, considering all the different forms of messages it enables you to create. The real trick is in providing appropriate messages to users and appropriate times. In addition to considering the icon and buttons to display in a message, you should follow these guidelines for crafting message text.

  • Use a formal tone. Don't use large words, and avoid using contractions. Strive to make the text immediately understandable and not overly fancy; a message box is not a place to show off your literary skills.
  • Limit messages to two or three lines. Lengthy messages are not only harder for users to read, but they can also be intimidating. When a message box is used to ask a question, make the question as simple as possible.
  • Never make users feel as though they've done something wrong. Users will, and do, make mistakes, but you should craft messages that take the sting out of the situation.
  • Spell check all message text. Visual Studio's code editor doesn't spell check for you, so you should type your messages into a program such as Word and spell check the text before pasting it into your code. Spelling errors have an adverse effect on a user's perception of a program.
  • Avoid technical jargon. Just because someone uses software doesn't mean that he or she is a technical person; explain things in plain English.
>

Creating Custom Dialog Boxes

Most of the time, the MessageBox.Show() method should be a sufficient means to display messages to a user. At times, however, the MessageBox.Show() method is too limited for a given purpose. For example, suppose you wanted to display a lot of text and therefore wanted a message box that was sizable by the user.

Custom dialog boxes are nothing more than standard modal forms with one notable exception: one or more buttons are designated to return a dialog result, the same as the buttons on a message box shown with the MessageBox.Show() method.

You're now going to create a custom dialog box. Create a new Windows Application titled Custom Dialog Example. Change the name of the default form to fclsMain, set its Text property to Custom Dialog Box Example, and set the Main() entry point of the project to reference fclsMain rather than Form1. Add a new button to the form and set its properties as follows:

Property Value
Name btnShowCustomDialogBox
Location 72,180
Size 152,23
Text Show Custom Dialog Box

Next, you're going to create the custom dialog box. Add a new form to the project by choosing Add Windows Form from the Project menu. Save the new form with the name fclsCustomDialogBox.cs. Change the Text property of the new form to This is a custom dialog box. Add a new text box to the form and set its properties as follows:

Property Value
Name txtCustomMessage
Location 8,8
Locked true
Multiline true
Size 276,224
Text Custom message goes here

For a custom dialog box to return a result like a standard message box does, it must have buttons that are designated to return a dialog result. This is accomplished by setting the DialogResult property of a button (see [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig06 Figure 18.6]).

Figure 18.6. The DialogResult property determines the return value of the button.

graphics/18fig06.jpg

Add a new button to the form and set its properties as shown in the following table. This button will act as the custom dialog box's Cancel button.

Property Value
Name btnCancel
DialogResult Cancel
Location 128,240
Size 75,23
Text Cancel

Last, you need to create an OK button for the custom dialog box. Create another button and set its properties as shown in the following table:

Property Value
Name btnOK
DialogResult OK
Location 208,240
Size 75,23
Text OK

Specifying a dialog result for one or more buttons is the first step in making a form a custom dialog box. The second part of the process is in how the form is shown. As you learned in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch05.htm#ch05 Hour 5], "Building Forms�Part I," forms are displayed by calling the Show method of the form or setting its visible property to true. However, to show a form as a custom dialog box, you call the ShowDialog method instead. When a form is displayed using ShowDialog, the following occurs:

  • The form is shown modally.
  • If the user clicks a button that has its DialogResult property set to return a value, the form is immediately closed and that value is returned as the result of the ShowDialog method call.

Notice how you don't have to write code to close the form; clicking a button with a dialog result closes the form automatically. This simplifies the process of creating custom dialog boxes. Return to the first form in the form designer by clicking the Form1.cs [Design] tab.

Double-click the button you created and add the following code:

fclsCustomDialogBox objCustomDialogBox = new fclsCustomDialogBox();

if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
 MessageBox.Show("You clicked OK.");
else
 MessageBox.Show("You clicked Cancel.");

objCustomDialogBox = null;

Press F5 to run the project, click the button to display your custom dialog box (see [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig07 Figure 18.7]), and then click one of the available dialog box buttons. When you're satisfied the project is working correctly, stop the project and save your work.

Figure 18.7. The ShowDialog method enables you to create custom message boxes.

graphics/18fig07.jpg

graphics/bookpencil.gif If you click the Close (X) button in the upper-right corner of the form, the form is closed and the code behaves as if you've clicked Cancel; the else code occurs.

The capability to create custom dialog boxes is a powerful feature. Usually, a call to MessageBox.Show() will suffice, but when you need more control over the appearance and contents of a message box, creating a custom dialog box is the way to go.

>

Interacting with the Keyboard

Most every control handles its own keyboard input; however, on occasion, you'll want to handle keyboard input directly. For example, you might want to perform an action when the user presses a specific button or releases a specific button. Most controls support three events that you can use to work directly with keyboard input. These are listed in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18table04 Table 18.4].

Event Name Description
KeyDown Occurs when a key is pressed down while the control has the focus.
KeyPress Occurs when a key is pressed (the key has been pushed down and then released) while the control has the focus.
KeyUp Occurs when a key is released while the control has the focus.

These events fire in the same order in which they appear in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18table04 Table 18.4]. Suppose, for example, that the user presses a key while a text box has the focus. The following list shows how the events would fire for the text box:

  1. When the user presses a key, the KeyDown event fires.
  2. When the user releases a key, the KeyPress event fires.
  3. After the KeyPress event fires, the KeyUp event fires, completing the cycle of keystroke events.

You're now going to create a project that illustrates handling keystrokes. This project has a text box that will refuse to display the letter "k." Start by creating a new Windows Application titled Keyboard Example. Change the name of the default form to fclsKeyboardExample, set its Text property to Keyboard Example, and set the Main() entry point of the project to reference fclsKeyboardExample instead of Form1. Add a new text box to the form and set its properties as shown in the following table:

Property Value
Name txtInput
Location 24,80
Multiline true
Size 240,120
Text (make blank)

You're going to add code to the KeyPress event of the text box to "eat" keystrokes made with the letter "k." Select the text box on the form and open the events list in the Properties window (Remember, this is the lightning bolt icon). Scroll through the list and locate the KeyPress event. Next, double-click the KeyPress event to access it in code. Your code editor should look now look like [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig08 Figure 18.8].

Figure 18.8. The KeyPress event is a good place to handle keyboard entry.

graphics/18fig08.jpg

As you learned in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/ch04.htm#ch04 Hour 4], "Understanding Events," the e parameter contains information about the occurrence of this event. In the keyboard events, the e parameter contains information about the key being pressed; therefore, it's what you'll be using to work with the keystroke made by the user.

The key being pressed is available as the KeyChar property of the e parameter. You are going to write code that handles the keystroke when the key being pressed is "k." Add the following code to the KeyPress event:

if (e.KeyChar == 'k')
 e.Handled = true;
graphics/bookpencil.gif Be sure to surround the k with single quotes, not double-quotes, because you're dealing with a character (char), not a string.

I would imagine that you're curious about the Handled property of the e object. When you set this property to true, you are telling C# that you handled the keystroke, and C# should ignore it. To see the effect this has, press F5 to run the project and enter the following into the text box:

Heard any good jokes lately?

What you'll end up with is the text shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig09 Figure 18.9].

Figure 18.9. Notice how the letter k was "eaten" by your code.

graphics/18fig09.jpg

Go ahead, try to enter another "k"�you can't. Next, try to enter an uppercase "K"; C# allows you to do this because uppercase and lowercase characters are considered different characters. Want to catch all "Ks," regardless of case? You could do so by adding the OR (||) operand to your decision construct, like this:

if (e.KeyChar == 'k'|| e.KeyChar == 'K')
 e.Handled = true;
graphics/bookpencil.gif It's not often that I need to catch a keypress, but every now and then I do. The three keystroke events have always made it easy to do what I need to do, but if there's any caveat I've discovered, it's that you need to give careful consideration to which event you choose (such as KeyPress or KeyUp, for example). Different events work best in different situations, and the best thing to do is to start with what seems like the most logical event, test the code, and change the event if necessary.
>

Using the Common Mouse Events

As with keyboard input, most controls support mouse input natively; you don't have to write code to deal with mouse input. However, at times you need more control than that offered by the native functionality of a control. C# supports six events that enable you to deal with mouse input directly. These events are listed in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18table05 Table 18.5], in the order in which they occur.

Event Name Description
MouseEnter Occurs when the pointer enters a control.
MouseMove Occurs when the pointer moves over a control.
MouseHover Occurs when the pointer hovers over a control.
MouseDown Occurs when the pointer is over a control and a button is pressed.
MouseUp Occurs when the pointer is over a control and a button is released.
MouseLeave Occurs when the pointer leaves a control.

You're now going to build a project that illustrates interacting with the mouse, using the MouseMove event. This project will allow a user to draw on a form, much like you can draw in a paint program. Begin by creating a new Windows Application titled Mouse Paint. Change the name of the default form to fclsMousePaint, set its Text property to Paint with the Mouse, and set the Main() entry point of the project to reference fclsMousePaint instead of Form1.

Next, double-click the form to access its default event, the Load event. Enter the following statement into the load event:

m_objGraphics = this.CreateGraphics();

You've already used a graphics object a few times. What you're doing here is setting a graphics object to the client area of the form; any drawing performed on the object will appear on the form. Because you're going to draw to this graphics object each time the mouse moves over the form, there's no point in creating a new graphics object each time you need to draw to it. Therefore, you're going to make m_objGraphics a module-level variable, which will be instantiated only once�in the Load event of the form. Enter this statement below the opening curly-brace after the public class fclsMousePaint class declaration:

private Graphics m_objGraphics;

As I've said previously, you should always destroy objects when you're done with them. In this case, you want the object to remain in existence for the life of the form. Therefore, you'll destroy it in the Closed event of the form, which occurs when the form is unloaded. Return to the Form1.cs[Design] tab, open the events list in the Property window and double-click the Closed event to create and open the code window to the Closed event. Enter the following statement in the Closed event:

m_objGraphics.Dispose();

Your form should now look like the one shown in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig10 Figure 18.10].

The last bit of code you need to add is the code that will draw on the form. You're going to place code in the MouseMove event of the form to do this. First, the code will make sure the left mouse button is held down. If it's not, no drawing will take place; the user must hold down the mouse button to draw. Next, a rectangle will be created. The coordinates of the mouse pointer will be used to create a very small rectangle that will be passed to the DrawEllipse method of the graphics object. This has the effect of drawing a tiny circle right where the mouse pointer is positioned. Again, Return to the Form1.cs[Design] tab, open the events list in the Property window, and double-click the MouseMove event to create and open the code window to the MouseMove event. Add the following code to this event:

Rectangle rectEllipse = new Rectangle() ;

if (e.Button != MouseButtons.Left) return;

rectEllipse.X = e.X - 1;
rectEllipse.Y = e.Y - 1;
rectEllipse.Width = 2;
rectEllipse.Height = 2;

m_objGraphics.DrawEllipse(System.Drawing.Pens.Blue, rectEllipse);

Like all events, the e object contains information related to the event. In this example, you are using the X and Y properties of the e object, which is the coordinate of the pointer when the event fires. In addition, you're checking the Button property of the object to make sure the user is pressing the left button.

Your project is now complete! Save your work by clicking Save All on the toolbar, and then press F5 to run the project. Move your mouse over the form�nothing happens. Now, hold down the left mouse button and move the mouse. This time, you'll be drawing on the form (see [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#ch18fig11 Figure 18.11]).

Notice that the faster you move the mouse, the more space appears between circles. This shows you that the user is able to move the mouse faster than the MouseMove event can fire, so you can't get every single movement of the mouse. This is important to remember.

>

Summary

Forms and controls allow for a lot of flexibility in the way a user interacts with an application. However, solid interactivity goes beyond what is placed on a form. In this hour, you learned how to use the MessageBox.Show() method to create informational dialog boxes. You learned how to specify an icon, buttons, and even how to designate a specific button as the default button. You also learned some valuable tips to help you create the best messages possible. You'll create message boxes frequently, so mastering this skill is important.

Finally, you learned how to interact with the keyboard and the mouse directly, through numerous events. Sometimes, the mouse or keyboard capabilities of a control fall short of what you want to accomplish. By understanding the concepts presented in this hour, you can go beyond the native capabilities of controls to create a rich, interactive experience for your users.

Q&A
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#qad1e55907 Q1:] Is it possible to capture keystrokes at the form level, rather than capturing them in control events?
A1: Yes. For the form's keyboard-related events to fire when a control has the focus, however, you must set the form's KeyPreview property to true. The control's keyboard events will still fire, unless you set KeyAscii = 0 in the form's KeyPress event and KeyCode = 0 in the form's KeyDown event.
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/18.htm#qad1e55926 Q2:] You don't seem to always specify a button in your MessageBox.Show() statements throughout this book. Why?
A2: If you don't explicitly designate a button or buttons, C# displays the OK button. Therefore, if all you want is an OK button, you do not need to pass a value to the buttons argument.

Workshop

The Workshop is designed to help you anticipate possible questions, review what you've learned, and get you thinking about how to put your knowledge into practice. The answers to the quiz are in [file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01.htm#app01 Appendix A],"Answers to Quizzes/Exercises."

 Quiz 
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec18.htm#ch18ans01 1:] What minimal argument should you supply when calling MessageBox.Show()?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec18.htm#ch18ans02 2:] If you don't supply a value for the title parameter of MessageBox.Show(), what gets displayed in the title bar of the message?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec18.htm#ch18ans03 3:] What type of data is always returned by the MessageBox.Show() method?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec18.htm#ch18ans04 4:] Which event fires first, the KeyUp or KeyPress event?
[file:///C:/Documents%20and%20Settings/dani/Asztal/c%23in24h/app01lev1sec18.htm#ch18ans05 5:] How do you determine which button is being pressed in a mouse-related event?
Exercises
  1. Modify your custom dialog box project so that the OK button is the Accept button of the form. That way, the user has only to press Enter to dismiss the dialog box. Next, make the Cancel button the Cancel button of the form so that the user can press the Esc key to dismiss the form as well.
  2. Modify your mouse paint project so that the form clears each time the user starts drawing. Hint: Clear the graphics object in the MouseDown event.