Turn your Mobile Apps into m-commerce apps – Learn More!

You're Browsing As A Guest! Register Now...
Become a VB Expert!

Join 416,731 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,907 people online right now.Registration is fast and FREE... Join Now!



printing text file in landscape prints in normal not landscape Rate Topic: -----

#1 davincinewfie  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-December 07


Dream Kudos: 0

Share |

printing text file in landscape

Posted 05 January 2008 - 05:41 PM

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
		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)


Was This Post Helpful? 0
  • +
  • -


#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • Icon

Reputation: 1439
  • View blog
  • Posts: 8,320
  • Joined: 18-April 07


Dream Kudos: 0

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

Re: printing text file in landscape

Posted 05 January 2008 - 09:27 PM

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!" :snap:
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • Icon

Reputation: 1401
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07


Dream Kudos: 12950

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Re: printing text file in landscape

Posted 05 January 2008 - 10: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:

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 :)
Was This Post Helpful? 0
  • +
  • -

#4 davincinewfie  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-December 07


Dream Kudos: 0

Re: printing text file in landscape

Posted 06 January 2008 - 07:00 AM

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




View PostPsychoCoder, on 5 Jan, 2008 - 11:54 PM, said:

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:

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 :)

Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users