Solved

vb.net print screen ..

Posted on 2006-11-22
5
709 Views
Last Modified: 2008-02-01
Hi Folks,

I need some code that will allow me to print my program screen ( to be more precise.. print screen) to my network printer when i clicks a button on my win form.

Thks
0
Comment
Question by:niger007
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 18000637
Hi niger007,

I'd recommend looking at these code samples:

http://www.codeproject.com/tools/screen_snaper.asp
http://www.utmag.com/wconnect/wc.dll?9,7,10,1453

Cheers,
Hillwaaa
0
 

Author Comment

by:niger007
ID: 18000665
Kindly provide me some simple codes , will allow me print my win form when i clicks a button.
0
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 18000765
No worries - but this is all straight from the source code that you can download from http://www.utmag.com/wconnect/wc.dll?9,7,10,1453

Note that to use it, you will have to incorporate the FormUtils and PrintImage classes from the source code (probably after converting them to VB - so it's not THAT easy :)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Instantiate our PrintDocument
        Dim pi As PrintImage = New PrintImage()
        ' Get a bitmap of the screen
        pi.Bitmap = FormUtils.FormToBitmap(Me)
        If PreviewPrintScreen = True Then
            ' preview the print
            Dim preview As PrintPreviewDialog = New PrintPreviewDialog()
            preview.Document = pi
            preview.ShowDialog()
        Else
            ' print to the printer
            pi.Print()
        End If
    End Sub
0
 

Author Comment

by:niger007
ID: 18001182
Hi,

 FormUtils and PrintImage classes are in CS and i am very new to .NET programming so i wont be able to convert into vb.net. Any other altrnatives.

Is there any alternative way for me to print my form data grid into my local printer. Do i still need to follow the tedious method which u mentioned above to accomplish this task.

Niger
0
 
LVL 16

Accepted Solution

by:
Hillwaaa earned 250 total points
ID: 18001709
It depends - if you just want to print your data grid, then you could do the following:

Option 1 - use a custom DataGrid that has built in print functionality - you can download the source from:
    http://www.codeproject.com/vb/net/datagridex.asp
    or
    http://rustemsoft.com/print_datagrid.htm

Option 2 - print the contents of your existing DataGrid - download an example from:
    http://www.codeproject.com/vb/net/DataGrid_Printing_Class.asp


The long and short of it is that printing from VB .NET is never (at least from what I've seen/done) just a case of click a button and out it comes.  You always have to do a bit of setup first :(

Cheers,
Hillwaaa
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now