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
}

You might also like to view...
If you want to examine an input value without actually removing it from the input stream, you can apply a member function of cin to the variable ch, which you are to assume is a char type variable. Which of these does this task?
a. cin.get(ch); b. cin.put(ch); c. cin.peek(ch); d. cin.putback(ch);
The ________ Number Field Size property is used for very large numbers with a maximum of 15 significant digits
Fill in the blank(s) with correct word
A collection contains at least one item.
Answer the following statement true (T) or false (F)
In the Exclude Folders window, you can select files you do not want included in the backup process. ____________________
Answer the following statement true (T) or false (F)