What’s wrong with this code? The following code should draw a BlueViolet circle of diameter 4 that corresponds to the movement of the mouse. Find the error(s) in the following code:


private void FrmPainter_MouseMove(
object sender, System.Windows.Forms.MouseEventArgs e )
{
if ( m_blnshouldPaint == true )
{
Graphics objGraphic = Graphics();

objGraphic.FillEllipse = (
new SolidBrush( Color.BlueViolet ), e.Y, e.X, 5, 4 );
}

} // end method FrmPainter_MouseMove


The position arguments in the FillEllipse method have been transposed. Use

method CreateGraphics to initialize a Graphics object. A circle’s height and width must be equal, so the fourth argument passed to method FillEllipse should be 4. There should be no assignment operator between the word FillEllipse and the parenthesis. The complete incorrect code reads:





// Painter.cs (Incorrect)



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;



namespace Painter

{

///

/// Summary description for FrmPainter.

///


public class FrmPainter : System.Windows.Forms.Form

{

///

/// Required designer variable.

///


private System.ComponentModel.Container components = null;



private bool m_blnShouldPaint = true;



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());

}



// draws a violet ellipse wherever the mouse moves

private void FrmPainter_MouseMove(

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

{

if ( m_blnshouldPaint == true )

{

Graphics objGraphic = Graphics();

objGraphic.FillEllipse = (

new SolidBrush( Color.BlueViolet ), e.Y, e.X, 5, 4 );

}



} // end method FrmPainter_MouseMove



} // end class FrmPainter

}







The complete corrected code should read:



// Painter.cs (Correct)



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;



namespace Painter

{

///

/// Summary description for FrmPainter.

///


public class FrmPainter : System.Windows.Forms.Form

{

///

/// Required designer variable.

///


private System.ComponentModel.Container components = null;



private bool m_blnShouldPaint = true;



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() );

}



// draws a violet ellipse wherever the mouse moves

private void FrmPainter_MouseMove(

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

{

if ( m_blnshouldPaint == true )

{

Graphics objGraphic = CreateGraphics();

objGraphic.FillEllipse(

new SolidBrush( Color.BlueViolet ), e.X, e.Y, 4, 4 );

}



} // end method FrmPainter_MouseMove



} // end class FrmPainter

}



Computer Science & Information Technology

You might also like to view...

____ defines the requirements that will underlie how separation of duties and least privilege will be assigned, and it underwrites the enforcement of individual accountability.

A. Scanning B. Screening C. Treating D. Reviewing

Computer Science & Information Technology

Explain the use of leases in a discovery service to cope with the problem of service volatility.

What will be an ideal response?

Computer Science & Information Technology

________ provides a short text description of an image

A) Image text B) Inline text C) Src text D) Alternate text

Computer Science & Information Technology

For intrasite replication, what component builds a replication topology for DCs in a site and establishes replication partners?

A. Kerberos B. PDC C. KCC D. Site link

Computer Science & Information Technology