|
Subject:
|
Beginning Visual C# Exercises - Chapter 15 Answers
|
|
Posted By:
|
seblake
|
Post Date:
|
9/24/2004 4:19:48 PM
|
1. The following adds menu pad under "Format", adds the "FontDialog" object, and handler code. ...Above the constructor // Adding the FontDialog object from the toolbox writes this code private System.Windows.Forms.FontDialog dlgFont;
...In the InitializeComponent() method dlgFont = new System.Windows.Forms.FontDialog(); // Change default font to match text box dlgFont.Font = textBoxEdit.Font; // Activate the apply button dlgFont.ShowApply = true; // Subscribe to the apply event dlgFont.Apply += new System.EventHandler(OnApplyFontDialog); // miFormatFont menu pad miFormatFont.Index = 0; miFormatFont.Text = "&Font"; miFormatFont.Click += new System.EventHandler(miFormatFont_Click);
...At the bottom of the code as handler to Color menu pad // Launch dialog for font change of text in textbox private void miFormatFont_Click(object sender, System.EventArgs e) { dlgFont.ShowDialog(); }
// When apply button is pressed within font dialog private void OnApplyFontDialog(object sender, System.EventArgs e) { textBoxEdit.Font = dlgFont.Font; }
...Revise two lines of code in this existing method private void OnPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) {
...Existing code ignored
//e.Graphics.DrawString(lines[linesPrinted++], new Font("Arial", 10), Brushes.Black, x, y); e.Graphics.DrawString(lines[linesPrinted++], textBoxEdit.Font, Brushes.Black, x, y); //y += 15; y += textBoxEdit.Font.Height;
...Existing code ignored }
2. The following adds menu pad under "Format", adds the "ColorDialog" object, and handler code. ...Above the constructor // Adding the ColorDialog object from the toolbox writes this code private System.Windows.Forms.ColorDialog dlgColor;
...In the InitializeComponent() method dlgColor = new System.Windows.Forms.ColorDialog(); // miFormatColor menu pad miFormatColor.Index = 1; miFormatColor.Text = "&Color"; miFormatColor.Click += new System.EventHandler(miFormatColor_Click);
...At the bottom of the code as handler to Color menu pad // Launch dialog for color change of text in textbox private void miFormatColor_Click(object sender, System.EventArgs e) { if (dlgColor.ShowDialog() == DialogResult.OK) textBoxEdit.ForeColor = dlgColor.Color; }
...Revise some code in this existing method private void OnPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { ...Existing code ignored
// Add following lines above the while loop Brush pageBrush = Brushes.Black; if (e.PageSettings.Color == true) pageBrush = new SolidBrush(textBoxEdit.ForeColor);
...Existing code ignored
//e.Graphics.DrawString(lines[linesPrinted++], new Font("Arial", 10), Brushes.Black, x, y); //e.Graphics.DrawString(lines[linesPrinted++], textBoxEdit.Font, Brushes.Black, x, y); e.Graphics.DrawString(lines[linesPrinted++], textBoxEdit.Font, pageBrush, x, y);
...Existing code ignored }
|
|
Reply By:
|
bmains
|
Reply Date:
|
9/27/2004 9:30:23 AM
|
Were all of these posts necessary for something?
|
|