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!

Crystal reports 1

Status
Not open for further replies.
Apr 12, 2004
98
US
I have a vb app that I'm working on building. A user fills out a form (data saves to SQL server). I want the user to print just that form with just the data that was just entered. I have been looking at Crystal reports but can't figure out if I can print current form. If I wanted to pull data out of the SQL database this would work fine but is there anyway to point to the current form using Crystal reports??

Lizzie
 
I don't think you can print the current form using CR. There are other ways of printing a form in VB 6, search the MSDN for "print". Not sure if you're in .Net though.

-Rick

----------------------
 
Thank you! Didn't think I could print current report after working with it for a little bit. Nice tool to use at month end or something though. I am using .NET.
 
Use the PrintDocument class. I would think it easier and possibly better to print out the DATA on the form, not the exact screen image. PrintDocuments are easy to use.
 
You should be able to print the current CR if you have it embedded on a form or user control. If I remember correctly the CR viewer object has print functionality built in.

-Rick

----------------------
 
The following works for me but now it just captures what is on the screen and not my whole form. Is there a way to capture my whole form??

Private Sub Print_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Print.Click
CaptureScreen()
PrintDocument1.Print()
End Sub

Thanks in advance
 
No one can tell by that code what it is doing. You have a CaptureScreen function, but you aren't showing what is in that function. You also aren't showing what is painted to the PrintDocument.
 
Sorry!

Private Sub CaptureScreen()
Dim mygraphics As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
Dim dc1 As IntPtr = mygraphics.GetHdc
Dim dc2 As IntPtr = memoryGraphics.GetHdc
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, _
Me.ClientRectangle.Height, dc1, 0, 0, 13369376)
mygraphics.ReleaseHdc(dc1)
memoryGraphics.ReleaseHdc(dc2)
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument1.PrintPage
e.Graphics.DrawImage(memoryImage, 0, 0)
End Sub

Private Sub PrintButton_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintButton.Click
CaptureScreen()
PrintDocument1.Print()
End Sub
 
I am not the best resource as far as graphics go--but I can tell you I highly doubt it. I don't think you can capture a screen that doesn't exist.

Your best bet is to print out a representation of what is on your form.

In your PrintDocument_PrintPage() event, you have a graphics object as you can see. You can draw text onto that graphics object. If you have 10 textboxes with data, well then, you draw 10 strings on your graphics object of the PrintDocument.

For example:

Code:
Dim g As Graphics = e.Graphics
g.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Black, 10, 10)
g.DrawString(TextBox2.Text, TextBox2.Font, Brushes.Black, 10, 25)

You would continue drawing strings for all your textboxes. You can even draw rectangles around them, as well as titles above, below or beside them.
 
I haven't played with the CR in .Net, but you may be able to build a dataset off of the data entered on your forma and send it to a CR report to print.

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top