|
-
Mar 26th, 2010, 11:25 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Which event should i use?
here is my entire code:
Code:
Imports System.Data.OleDb
Public Class Form1
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim da As OleDbDataAdapter
Private _titleFont As Font
Private _detailFont As Font
Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
'set the data pointers (if any) to the start position
'initialise any page number variables you might have
_titleFont = New Font(FontFamily.GenericSerif, 16, FontStyle.Bold, GraphicsUnit.Point)
_detailFont = New Font(FontFamily.GenericSerif, 9, FontStyle.Bold, GraphicsUnit.Point)
End Sub
Private Sub PrintDocument1_EndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.EndPrint
'You can use this event handler to clear up any objects that you have created for the print job
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'All of the actual printing on a page is done in the PrintPage event handler
'This event is raised for each page that is printed
'the drawing and text commands that you code in this event handler control what is printed on the page itself
Dim xPos As Single = 20
Dim yPos As Single = 20
Dim i As Integer = 0
For Each rows As DataRow In dt.Rows
e.Graphics.DrawString(dt.Rows(i).Item(0).ToString, _detailFont, Brushes.Black, xPos, yPos)
xPos += e.Graphics.MeasureString(dt.Rows(i).Item(0).ToString, _detailFont).Width
e.Graphics.DrawString(dt.Rows(i).Item(1).ToString, _detailFont, Brushes.Black, xPos, yPos)
xPos += e.Graphics.MeasureString(dt.Rows(i).Item(1).ToString, _detailFont).Width
e.Graphics.DrawString(dt.Rows(i).Item(2).ToString, _detailFont, Brushes.Black, xPos, yPos)
xPos += e.Graphics.MeasureString(dt.Rows(i).Item(2).ToString, _detailFont).Width
e.Graphics.DrawString(dt.Rows(i).Item(3).ToString, _detailFont, Brushes.Black, xPos, yPos)
xPos = 20
yPos += 20
i += 1
Next
End Sub
'if there are more pages to print, set the e.HasMorePages property to True
'and the QueryPageSettings and PrintPage events will be triggered again
'the same event handler is used, so if you want to print different pages
'you need to keep track of which page you are on and code your PrintPage event handler accordingly
Dim dt As New DataTable
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
Private Sub PrintDocument1_QueryPageSettings(ByVal sender As Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) Handles PrintDocument1.QueryPageSettings
'raised before each and every page that is printed
'use this event to set any page settings for the next page to be printed
'set the orientation (landscape or portrait), the paper size, paper source, and so on
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
con = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=db1.mdb")
con.Open()
cmd = New OleDbCommand("Select * from Table1 where Roll='31'", con)
da = New OleDbDataAdapter(cmd)
da.Fill(dt)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
PageSetupDialog1.PageSettings = PrintDocument1.DefaultPageSettings
If PageSetupDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
Else
Exit Sub
End If
End Sub
End Class
the print preview dialog works greta but i am having simple problem:
have a look at this image:

The leftmost print button will print the document and as soon as i click it,the printing begins.
All i want to do is to display the print dialog to it as soon as the leftmost print button is clicked an then i want to start the printing when the print button of the print dialog is clicked.
But i dont know if there is some event to do this or some other ideas.....
Please help
thank you
-
Mar 27th, 2010, 02:35 AM
#2
Re: Which event should i use?
i had the same issue and just ended up showing the print dialogue prior to showing the print preview in the end
Kris
-
Mar 27th, 2010, 03:00 AM
#3
Thread Starter
Fanatic Member
Re: Which event should i use?
In this case i want to show the print preview first,then on clicking the print button (the leftmost one shown in the #1 image) then print dialog will appear and the on clicking the print button present in the print dialog,the printing will take place.this is all i want to do.I hope that jmc or merrion would have a look at this thread and would help both of us to do exactly what we want to do.....
-
Mar 27th, 2010, 05:47 AM
#4
Thread Starter
Fanatic Member
Re: Which event should i use?
-
Mar 27th, 2010, 06:28 AM
#5
Re: Which event should i use?
There is no law that says that you have to use a PrintPreviewDialog. If you do then you have to accept the way it works. If you don't like the way it works then don't use it. Create your own form and put a PrintPreviewControl on it. You can then make it work however you want.
-
Mar 27th, 2010, 06:38 AM
#6
Thread Starter
Fanatic Member
Re: Which event should i use?
ok i will have a look at the print preview control
thanks
-
Mar 27th, 2010, 06:47 AM
#7
Re: Which event should i use?
 Originally Posted by HowTo
ok i will have a look at the print preview control
thanks
To clarify, the PrintPreviewDialog is just a form with a PrintPreviewControl on it and some other functionality built in. Like I said, there's no reason you can't create your own form with the same control and your own functionality built in. Another advantage is that you get to match it to the rest of your UI.
-
Mar 27th, 2010, 07:09 AM
#8
Thread Starter
Fanatic Member
Re: Which event should i use?
so it means it is not possible to change or add something new to the built in functionality of the PrintPreviewDialogl right?In that case i need to use the PrintPreviewControl,right?
-
Mar 27th, 2010, 07:15 AM
#9
Re: Which event should i use?
 Originally Posted by HowTo
so it means it is not possible to change or add something new to the built in functionality of the PrintPreviewDialogl right?In that case i need to use the PrintPreviewControl,right?
The PrintPreviewDialog class is not declared NotInheritable so, in theory, you could derive your own class from it and add or modify its functionality. Whether or not you'll be able to do what you want in that way depends on what members are Private or Friend and which are Public or Protected.
-
Mar 27th, 2010, 07:25 AM
#10
Thread Starter
Fanatic Member
Re: Which event should i use?
 Originally Posted by jmcilhinney
you could derive your own class from it and add or modify its functionality.
then how to proceed with the PrintPreviewDialog what i wanted to do in #3?
Please help
-
Mar 27th, 2010, 06:14 PM
#11
Re: Which event should i use?
i thought about making my own because i didnt like the way the built in one does multi pages ... would just rather scroll through the pages ... in the end didnt bother tho it would be fairly easy since the pages are effectively just images...
Kris
-
Mar 27th, 2010, 07:55 PM
#12
Re: Which event should i use?
 Originally Posted by HowTo
then how to proceed with the PrintPreviewDialog what i wanted to do in #3?
Please help
You seem to assume that it's possible. I doubt that it is. Have you looked through the members of the PrintPreviewDialog? Is there any event raised when that button is clicked? If you can't find one then that would suggest that there isn't one. In that case you will have to do as I suggested in the first place: create your own form.
-
Mar 27th, 2010, 09:58 PM
#13
Re: [RESOLVED] Which event should i use?
well like i said it wouldnt be hard to make your own ... and a better one with out using the built in printpreviewdialogue
Kris
-
Mar 27th, 2010, 10:05 PM
#14
Thread Starter
Fanatic Member
Re: [RESOLVED] Which event should i use?
help me out here:
http://www.vbforums.com/showthread.php?t=608974
http://www.vbforums.com/showthread.php?t=608914
these are all related one but since different questions,i have created different threads
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|