Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   .Net printing (http://www.programmingforums.org/showthread.php?t=14652)

Jabo Dec 1st, 2007 1:28 AM

.Net printing
 
Does anybody know any good .net printing tutorials? This seems to be a little touched area. Thanks and I will dance at your wedding.

Before you post anything from msdn, I'm already looking at this and trying to understand it.

Pizentios Dec 1st, 2007 2:24 PM

Re: .Net printing
 
not sure how much detail you want in your prints. I found this here link on about.com, it shows how to get basic text printing. However that example doesn't provide wrapping, if you print a line that is too long it will be cut off on the right side of the page.

This link seems to be a little more indepth and even shows you how to create a print preview.

Hope that helps a little. I am not a VB.NET coder by any means but i do have some understanding of the language.

mattireland Dec 1st, 2007 3:35 PM

Re: .Net printing
 
There's loads of stuff on Visual Basic 6 for printing but not that much in VB.NET. You have to write quite a few lines of code - I'm not sure exactly how to do it. It's easy to print to a file but not so easy to get it out on paper.

Sorry I couldn't be more help,

Matt. I

Jabo Dec 1st, 2007 5:20 PM

Re: .Net printing
 
Yeah, VB6 printing was fairly easy, VB.Net is a bit more involved, but what I'm reading sounds to be more standardized and functional.

Right now, I'm just printing (hopefully) a single page.

Pizentios Dec 1st, 2007 5:55 PM

Re: .Net printing
 
if you take a look at those links, they show you how to do it in VB.NET.

Jabo Dec 1st, 2007 6:39 PM

Re: .Net printing
 
will do...just let me know when you're getting married lol

mattireland Dec 2nd, 2007 6:03 AM

Re: .Net printing
 
If you do manage please could you upload a piece of example code so that people looking back over this thread in the future (i.e. me) might have an idea of how to do it without following external links?

cornboy88 Dec 4th, 2007 10:26 AM

Re: .Net printing
 
Try this it may help.

Visual Basic Power Pack

http://www.microsoft.com/downloads/d...displaylang=en

hollystyles Dec 7th, 2007 5:04 AM

Re: .Net printing
 
.NET makes it very easy. I realise this is C# in a VB forum but obviously the principal is the same and VB Syntax just makes my teeth jangle a bit like fingernails on a blackboard, sorry.

:

using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;

public partial class MyPrintWindow : Form
{
    private int currentPage = 1;

    public MyPrintWindow()
    {
                InitializeComponent();
    }
   
    //This can be your menu item click event or whatever you require.
    private void btnPrint_Cick(object sender, EventArgs e)
    {
            try
            {
                this.currentPage = 1;

                PrintDocument pd = new PrintDocument();

                pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
 
                PrintDialog pDlg = new PrintDialog();
               
                DialogResult dlgResult = pDlg.ShowDialog();
                if (dlgResult == DialogResult.OK)
                {
                    pd.Print();
                }
            }
            catch(Exception ex)
            {
                        //do your favourite error handling here
                        //messagebox, log entry blah...
            }
    }

    private void pd_PrintPage(object sender, PrintPageEventArgs e)
    {
              e.Graphics.DrawString("Hello", new Font("Arial", 8f), Brushes.Black, new PointF(0f, 0f));
              ++currentPage;

              //Apply your own logic here as to whether more pages are due.
              //In my simple example there is only one page.
              e.HasMorePages = false;
    }
}


Jabo Sep 21st, 2008 10:43 AM

Re: .Net printing
 
Sorry for the delay, but here is how I did it.
:

  1. If PrintingActiveToolStripMenuItem.Checked = True Then
  2.     PrntDoc.Print()
  3. End If

:

  1. Private Sub PrntDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrntDoc.PrintPage
  2.     'set printdoc contents to print errstring message
  3.     e.Graphics.DrawString(errstring, Me.Font, Brushes.Black, 20, 20)
  4.     e.HasMorePages = False
  5. End Sub


errstring is a string I built earlier in the code and is what is being printed. This is a simplified print with nearly non-existent formatting. The string provides the only formatting there is. There is no check for line length; I guestimated that the way I set everything up there would be no need. I would have to go into a bit more depth if I actually needed to format anything, such as adding a printdocument to the application that would handle all formatting for me according to settings.


All times are GMT -5. The time now is 12:46 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC