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 !