Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > BOOK: Beginning Visual C#
|
BOOK: Beginning Visual C#
This is the forum to discuss the Wrox book Beginning Visual C#, Revised Edition of Beginning C# for .NET v1.0 by Karli Watson, David Espinosa, Zach Greenvoss, Jacob Hammer Pedersen, Christian Nagel, Jon D. Reid, Matthew Reynolds, Morgan Skinner, Eric White; ISBN: 9780764543821
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 24th, 2004, 04:19 PM
Authorized User
 
Join Date: Jul 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning Visual C# Exercises - Chapter 15 Answers

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

            <s>//e.Graphics.DrawString(lines[linesPrinted++], new Font("Arial", 10), Brushes.Black, x, y);</s>
            e.Graphics.DrawString(lines[linesPrinted++], textBoxEdit.Font, Brushes.Black, x, y);
            <s>//y += 15;</s>
            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

            <s>//e.Graphics.DrawString(lines[linesPrinted++], new Font("Arial", 10), Brushes.Black, x, y);</s>
            <s>//e.Graphics.DrawString(lines[linesPrinted++], textBoxEdit.Font, Brushes.Black, x, y);</s>
            e.Graphics.DrawString(lines[linesPrinted++], textBoxEdit.Font, pageBrush, x, y);

            ...Existing code ignored
        }
 
Old September 27th, 2004, 09:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Were all of these posts necessary for something?









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.