Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VS2005: PrintDocument programmatorically add EventHandlers

Posted on 2006-07-20
2
Medium Priority
?
314 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
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

810 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