What is the result of the following code? Assume the Form contains a MainMenu con- trol, with a MenuItem named mnuitmColor. Also assume the Form contains a Label called lblMystery.
private void mnuitmColor_Click( object sender, System.EventArgs e )
{
ColorDialog dlgColorDialog = new ColorDialog();
DialogResult result;
dlgColorDialog.FullOpen = true;
result = dlgColorDialog.ShowDialog();
if ( result == DialogResult.Cancel )
{
return;
}
1 lblMystery.BackColor = dlgColorDialog.Color;
} // end method mnuitmColor_Click
When this event handler executes, the Color dialog is displayed. If the user chooses a color, that color is assigned to the BackColor of lblMystery. If the dialog’s Cancel Button is clicked, the dialog closes and this event handler terminates. The complete code reads:
// ColorChanger.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace ColorChanger
{
///
/// Summary description for FrmColorChanger.
///
public class FrmColorChanger : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mnuMainMenu;
private System.Windows.Forms.MenuItem mnuitmForm;
private System.Windows.Forms.MenuItem mnuitmColor;
private System.Windows.Forms.Label lblMystery;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public FrmColorChanger()
{
//
// 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 FrmColorChanger() );
}
// changes the Form's color
private void mnuitmColor_Click(
object sender, System.EventArgs e )
{
ColorDialog dlgColorDialog = new ColorDialog();
DialogResult result;
dlgColorDialog.FullOpen = true;
result = dlgColorDialog.ShowDialog();
if ( result == DialogResult.Cancel )
{
return;
}
lblMystery.BackColor = dlgColorDialog.Color;
} // end method mnuitmColor_Click
} // end class FrmColorChanger
}
Computer Science & Information Technology
You might also like to view...
The BIOS/UEFI can be used to repair operating system files
Indicate whether the statement is true or false
Computer Science & Information Technology
A(n) ____ file is a separate file that is saved in the same folder as the camera raw file and holds all of the adjustment data.
a. XMP b. TIFF c. BMP d. JPEG
Computer Science & Information Technology