Consider the example in Fig. 21.27. Suppose we change the MouseMove event handler to the code below. What happens when the user moves the mouse? Assume that the lblDis- play Label has been placed on the Form.


private void FrmPainter_MouseMove(
object sender, System.Windows.Forms.MouseEventArgs e )
{
lblDisplay.Text = "I'm at " + e.X + ", " + e.Y + ".";

} // end method FrmPainter_MouseMove


The Label continuously displays the mouse pointer’s current position on the Form.

The complete code reads:



// Painter.cs



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;



namespace MousePointer

{

///

/// Summary description for FrmPainter.

///


public class FrmPainter : System.Windows.Forms.Form

{

private System.Windows.Forms.Label lblPosition;

private System.Windows.Forms.Label lblDisplay;

///

/// Required designer variable.

///


private System.ComponentModel.Container components = null;



public FrmPainter()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();



//

// TODO: Add any constructor code after InitializeComponent

// call

//

}



///

/// Clean up any resources being used.

///


protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}



// Windows Form Designer generated code



///

/// The main entry point for the application.

///


[STAThread]

static void Main()

{

Application.Run( new FrmPainter() );

}



// displays the mouse's current x and y coordinates

private void FrmPainter_MouseMove(

object sender, System.Windows.Forms.MouseEventArgs e )

{

lblDisplay.Text = "I'm at " + e.X + ", " + e.Y + ".";

} // end method FrmPainter_MouseMove



} // end class FrmPainter

}



Computer Science & Information Technology

You might also like to view...

You can position a billboard by using the ____ button. 

A. orient shot B. orient scene C. one shots D. one scenes

Computer Science & Information Technology

Which of the following statements initializes the unsigned int variable counter to 10?

a. unsigned int counter = 10; b. unsigned int counter = {10}; c. unsigned int counter{10}; d. All of the above.

Computer Science & Information Technology

Some people use a password ________ to store passwords so they do not have to remember all of them

Fill in the blank(s) with correct word

Computer Science & Information Technology

The option element is NOT a self-closing tag

Indicate whether the statement is true or false

Computer Science & Information Technology