Welcome to Dream.In.Code
Become a VB Expert!

Join 149,945 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,403 people online right now. Registration is fast and FREE... Join Now!




printing text file in landscape

 
Reply to this topicStart new topic

printing text file in landscape, prints in normal not landscape

davincinewfie
5 Jan, 2008 - 05:41 PM
Post #1

New D.I.C Head
*

Joined: 15 Dec, 2007
Posts: 3


My Contributions
this is going to sound stupid but I am trying to print a text file I am not sure why this works but this code below prints the file but I need to get it printed in landscape and since printing in vb 2005 studio is way different that 6.0 I need all the help I can get
CODE

        Call tabfile()
        Dim piStart As New ProcessStartInfo
        With piStart
            .FileName = System.Windows.Forms.Application.StartupPath & "\tabhamlog.txt"
            .Verb = "print"
            .WindowStyle = ProcessWindowStyle.Hidden
        End With
        Process.Start(piStart)

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Printing Text File In Landscape
5 Jan, 2008 - 09:27 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You know why this works? Because you are starting a process to open up the text file which launches the program associated with txt files, probably notepad. It then passes a print command to it. So it is opening up notepad and calling print.

However this is not the standard way for printing and .NET does it much better and nicer. To do it you will have to look to your toolbox for the printDialog control and the printdocument control, adding both to your project.

Your printdialog control will be for the dialog screen where you can setup printer settings like landscaping or portrait. Once you got the settings, you would set the printdocument control's printsettings property equal to the printdialog printsettings and handle the printdocument's printpage event for sending data to the printer.

Below is a great site I found which will show you a bit of the code behind this. The example also includes a pagesetup screen and print preview so you can leave those out if you want to keep it simple.

Printing in VB.NET

Enjoy!

"At DIC we be printing code ninjas!" decap.gif
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Printing Text File In Landscape
5 Jan, 2008 - 10:54 PM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Listen to Martyr2, VB.Net added lots for printing. In code you cannot access properties of the printers connected to your pc (or even a Network printer)

Thants why the .Net Framework offered the PrintDialog Class which gives the user the abilit to select what they want. Heres a small example:

CODE

Private WithEvents doc As New Printing.PrintDocument

    ' Set the properties of the PrintDocument
    'before showing the dialog
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            ' Setting to tru allows user to select range
            'of pager to print
            'set to false if you want the user to print whole documdnt only
            testPrintDialog.AllowSomePages = True

            ' Show the help button.
            testPrintDialog.ShowHelp = True

            ' Set the Document property to the PrintDocument for
            ' which the PrintPage Event has been handled. To display the
            ' dialog, either this property or the PrinterSettings property
            ' must be set
            testPrintDialog.Document = doc
            'Create property to show the dialog
            Dim printResults As DialogprintResults = testPrintDialog.ShowDialog()

            ' If the printResults is OK then print the document.
            If (printResults = DialogprintResults.OK) Then
                doc.Print()
            End If
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
     End Sub


Just set the propetties of the PrintDialog Class, one you have the requirements you need call the [url=http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.print.aspx]PrintMethod} to print the document.

Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

davincinewfie
RE: Printing Text File In Landscape
6 Jan, 2008 - 07:00 AM
Post #4

New D.I.C Head
*

Joined: 15 Dec, 2007
Posts: 3


My Contributions
thanks for all the help thus far looks like I got some reading and figguring out to do
been away from vb for a while hard to get back into it when soo many things have changed

thanks a million




QUOTE(PsychoCoder @ 5 Jan, 2008 - 11:54 PM) *

Listen to Martyr2, VB.Net added lots for printing. In code you cannot access properties of the printers connected to your pc (or even a Network printer)

Thants why the .Net Framework offered the PrintDialog Class which gives the user the abilit to select what they want. Heres a small example:

CODE

Private WithEvents doc As New Printing.PrintDocument

    ' Set the properties of the PrintDocument
    'before showing the dialog
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            ' Setting to tru allows user to select range
            'of pager to print
            'set to false if you want the user to print whole documdnt only
            testPrintDialog.AllowSomePages = True

            ' Show the help button.
            testPrintDialog.ShowHelp = True

            ' Set the Document property to the PrintDocument for
            ' which the PrintPage Event has been handled. To display the
            ' dialog, either this property or the PrinterSettings property
            ' must be set
            testPrintDialog.Document = doc
            'Create property to show the dialog
            Dim printResults As DialogprintResults = testPrintDialog.ShowDialog()

            ' If the printResults is OK then print the document.
            If (printResults = DialogprintResults.OK) Then
                doc.Print()
            End If
        Catch Ex As Exception
            MessageBox.Show(Ex.Message)
        End Try
     End Sub


Just set the propetties of the PrintDialog Class, one you have the requirements you need call the [url=http://msdn2.microsoft.com/en-us/library/system.drawing.printing.printdocument.print.aspx]PrintMethod} to print the document.

Hope that helps smile.gif


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 05:01PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month