Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the 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 9th, 2004, 05:39 PM
Authorized User
 
Join Date: Jul 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning Visual C# Exercises - Chapter 15

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 17th, 2004, 08:41 PM
Authorized User
 
Join Date: Jun 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Keep up a good work. Appreicate it!!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning Visual C# Exercises - Chapter 14 seblake C# 0 September 8th, 2004 06:19 PM
Beginning Visual C# Exercises - Chapter 10 seblake C# 1 July 29th, 2004 05:10 PM
Beginning Visual C# Exercises - Chapter 04 seblake C# 0 July 21st, 2004 09:21 AM
Beginning Visual C# Exercises - Chapter 06 seblake C# 1 July 19th, 2004 09:15 AM





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