Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Improvement of the .NET Menu Style class

, 14 Jan 2003
This is an improvement by Francesco Natali over an improvement by Sajith M of the "Visual Studio .NET Menu Style" by Carlos H. Perez
myrtf editor.zip
backimage.jpg
bin
Debug
Release
Icone
about.ico
Application.ico
arrange.ico
binoc.ico
chars.ico
Child.ico
close.ico
copy.ico
cut.ico
delete.ico
find.ico
font.ico
gotonet.ico
lock.ico
lowercase.ico
net.ico
new.ico
open.ico
paste.ico
preference.ico
printer.ico
recentfiles.ico
redo.ico
save.ico
selectedtext.ico
turnoff.ico
undo.ico
uppercase.ico
ModifyRegistry.zip
myRTF Editor.csproj.user
myRTF Editor.suo
paper01.jpg
paper02.jpg
paper03.jpg
myrtfeditor.zip
backimage.jpg
about.ico
Application.ico
arrange.ico
binoc.ico
chars.ico
Child.ico
close.ico
copy.ico
cut.ico
delete.ico
find.ico
font.ico
gotonet.ico
lock.ico
lowercase.ico
net.ico
new.ico
open.ico
paste.ico
preference.ico
printer.ico
recentfiles.ico
redo.ico
save.ico
selectedtext.ico
turnoff.ico
undo.ico
uppercase.ico
ModifyRegistry.zip
myRTF Editor.csproj.user
paper01.jpg
paper02.jpg
paper03.jpg
nicemenu.zip
nicemenu2.zip
prjnicemenu.zip
App.ico
prjNiceMenu.exe
prjNiceMenu.pdb
nicemenu.png
obj
Debug
MenuSample.Form1.resources
prjNiceMenu.exe
prjNiceMenu.exe.incr
prjNiceMenu.NiceMenu.resources
prjNiceMenu.pdb
prjNiceMenu.projdata
prjProvaFunzioni.projdata
temp
TempPE
prjNiceMenu.csproj.user
prjNiceMenu.suo
//------------------------------------------------------------------------------
/// <copyright from='1997' to='2001' company='Microsoft Corporation'>
///    Copyright (c) Microsoft Corporation. All Rights Reserved.
///
///    This source code is intended only as a supplement to Microsoft
///    Development Tools and/or on-line documentation.  See these other
///    materials for detailed information regarding Microsoft code samples.
///
/// </copyright>
//------------------------------------------------------------------------------
namespace myRTF_Editor {
    using System;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Printing;
    using System.IO;

    // <doc>
    // <desc>
    //     TextFilePrintDocument prints a stream to a printer
    //
    //     Note: In order to avoid problems closing a file
    //     if an exception occurs this class simply takes a
    //     steam and leaves it to the caller to open the file
    //     to print
    //
    // </desc>
    // </doc>
    public class TextFilePrintDocument : PrintDocument {
        private Font printFont           = null ;
        private StreamReader streamToPrint = null ;

        public TextFilePrintDocument(StreamReader streamToPrint) : base ()  {
            this.streamToPrint = streamToPrint ;
        }

        //Override OnBeginPrint to set up the font we are going to use
        protected override void OnBeginPrint(PrintEventArgs ev) {
            base.OnBeginPrint(ev) ;
            printFont = new Font("Arial", 10);
        }

        //Override the OnPrintPage to provide the printing logic for the document
        protected override void OnPrintPage(PrintPageEventArgs ev) {

            base.OnPrintPage(ev) ;

            float lpp = 0 ;
            float yPos =  0 ;
            int count = 0 ;
            float leftMargin = ev.MarginBounds.Left;
            float topMargin = ev.MarginBounds.Top;
            String line=null;

            //Work out the number of lines per page
            //Use the MarginBounds on the event to do this
            lpp = ev.MarginBounds.Height  / printFont.GetHeight(ev.Graphics) ;

            //Now iterate over the file printing out each line
            //NOTE WELL: This assumes that a single line is not wider than the page width
            //Check count first so that we don't read line that we won't print
            while (count < lpp && ((line=streamToPrint.ReadLine()) != null)) {
                yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));

                ev.Graphics.DrawString (line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());

                count++;
            }

            //If we have more lines then print another page
            if (line != null)
                ev.HasMorePages = true ;
            else
                ev.HasMorePages = false ;
        }

    }

}







By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Francesco Natali
Web Developer
Italy Italy
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 15 Jan 2003
Article Copyright 2002 by Francesco Natali
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid