Solved

VS2005: PrintDocument programmatorically add EventHandlers

Posted on 2006-07-20
2
300 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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

14 Experts available now in Live!

Get 1:1 Help Now