Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VS2005: PrintDocument programmatorically add EventHandlers

Posted on 2006-07-20
2
Medium Priority
?
312 Views
Last Modified: 2009-07-29
Hello fellow experts,

I'm trying to get some stuff printed; that's all not so difficult, well, you know, but I have this particular situation where I HAVE to programmatorically make the PrintDocument.

This ofcourse puts me in a difficult position; by programmatorically adding the PrintDocument, instead of during design, I also have to programmatorically assign the EventHandlers, and this is where things go awry.

This is the code:

    Private pd As New PrintDocument

        pd.PrinterSettings = New PrinterSettings()
        AddHandler pd.BeginPrint, PrintDocument1_BeginPrint(Me, New PrintEventArgs())
        Dim gr As Drawing.Graphics = Nothing
        AddHandler pd.PrintPage, PrintDocument1_PrintPage(Me, New PrintPageEventArgs(gr, New Drawing.Rectangle(), New Drawing.Rectangle(), New PageSettings()))


ok so first of, the AddHandler requires that I use FUNCTIONS as EventHandlers because it wants a return value; however, I don't want that (and it kinda fubars if it does). anyway, skipping the return value only gives me a warning if i use functions so ok, that's cool.

The second problem is, ofcourse, the EventArgs.
Adding Event Handlers in runtime requires you to add the right EventArgs aswell; I don't know these, so my code basically stops running on the AddHanlder pd.PrintPage line, giving me an error because gr is empty.

So, basically, what I need to know from the experts, is a way to add a printdocument and its eventhandlers (specifically the onBeginPrint and onPrintPage ones) during RUNTIME.

thanks in advance !

cheers,
Andy
0
Comment
Question by:AndyAelbrecht
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
jjardine earned 2000 total points
ID: 17147697
To get the correct event args  just create the events during design time and then remove the Handles clause.  Then when you call addhander during runtime you just do AddressOf the sub.

This would make your addHandler look like this

AddHandler pd.BeginPrint, AddressOf PrintDocument1_BeginPrint
0
 
LVL 4

Author Comment

by:AndyAelbrecht
ID: 17163420
*doh* :)

thx !
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

610 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