Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page Orientation

Status
Not open for further replies.

WJProctor

Programmer
Jun 20, 2003
151
GB
Hi there,

I want to force the orientation of a page so that its landscape instead of portrate. Is this possible with vb.net or not?

Thanks

JP
 
Yeah, sorry i meant when printing, I dont want the user to be able to change it to portrate, but just force it to be landscape.

Thanks

JP
 
HI
If are using PrintDialog box for it? if yes then
if Me.PrintDialog1.PrinterSettings.DefaultPageSettings.Landscape = flase
Msgbox ("Can't Print in Portrait Mode)
Else
'Print it
End If

Nouman Zaheer
Software Engineer
MSR
 
Ok another question lol, What about printing on multiple pages, how do i move onto a new page. Is this possible?? Hope you can help out.

Regards

JP
 
Hi
Here is the sample code for printing with some what more control on printing

HI
it will do what u want,let me know if it works for u
Nouman
Imports System.IO
Imports System.Drawing.Printing 'For printing

Private Sub btnPrintLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintLog.Click
Dim strFile As String
PrintLogFile(strFile) 'File path to print
End Sub
' The PrintPage event is raised for each page to be printed.
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim linesPerPage As Single = 0
Dim yPos As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing

' Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

' Iterate over the file, printing each line.
While count < linesPerPage
line = streamToPrint.ReadLine()
If line Is Nothing Then
Exit While
End If
yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
yPos, New StringFormat())
count += 1
End While

' If more lines exist, print another page.
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
End Sub

' Print the file.
Public Sub PrintLogFile(ByVal filePath As String)
Try
streamToPrint = New StreamReader(filePath)
Try
printFont = New Font(&quot;Arial&quot;, 10)
Dim pd As New PrintDocument()
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Print the document.
pd.Print()
Finally
streamToPrint.Close()
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub 'Printing

Nouman Zaheer
Software Engineer
MSR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top