Determine whether Graphics object is for a printer
I'll preface this by saying that I'm posting this on behalf of my boss so I haven't done any research myself, although he's been working on the problem for a while so I'm sure he's done his due diligence.
We would like to know whether there is any way to interrogate a Graphics object and determine whether it is to be used to print or to render to some other canvas. We're aware of an API call that can be used but would prefer to avoid that route if possible. There's also the possibility of simply passing a flag in with the Graphics object that is True from a PrintPage event handler and False from elsewhere, but that's not ideal either. We're looking for a managed property or method accessible via the Graphics class itself, but nothing's jumping out. Any ideas?
Re: Determine whether Graphics object is for a printer
I'll need to have a look in my printer code (which is at home) but I think you will need to go down the API route - either GetDeviceCaps or something in DEVMODE.
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
Merrion
I'll need to have a look in my printer code (which is at home) but I think you will need to go down the API route - either GetDeviceCaps or something in DEVMODE.
Thanks for your response Merrion. Yeah, my boss did mention GetDeviceCaps. As I said, he'd like to avoid that if possible but if it's the only way then it's the only way. I shall await your final conformation or denial. :)
Re: Determine whether Graphics object is for a printer
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
Pradeep1210
I'm afraid not. We have no specific access to a PrintDocument. The whole point is that we have a method that has a parameter of type Graphics. This method is called from the PrintPage event handler of a PrintDocument with e.Graphics passed as an argument. It is also called from elsewhere with the result Graphics.FromImage passed as an argument. The method simply calls methods of the Graphics object to draw on the appropriate canvas, which might be a printed page or it might be an Image. The problem is that there is one small thing that needs to be done differently depending on whether the canvas is a printed page or something else. We want to determine that from just the Graphics object.
Re: Determine whether Graphics object is for a printer
Since the Graphics class can't be inherited, I think the best way would be to pass an additional optional parameter for the device name, so that there is minimal change in existing code.
vb.net Code:
Private Sub MyGraphicsMethod(ByVal g As Graphics, Optional ByVal targetDevice As String = "")
Select Case targetDevice.ToLower
Case "printer"
Case Else
End Select
End Sub
Re: Determine whether Graphics object is for a printer
Hmm, interesting. I, also, have graphics routines that both print to the screen, and a printer page - I usually have a flag, as already mentioned, to the actual drawing routines which say if it's a printed page or not.
That is to say, there doesn't (didn't?) seem to be a unique identifier that indicates it's a printer from the graphics object.
Re: Determine whether Graphics object is for a printer
Still no joy - I think your best bet might be: GetDeviceCaps (API) with index set to: TECHNOLOGY.... but I can't see any way without resorting to an API call.
Re: Determine whether Graphics object is for a printer
Thank you everyone for your efforts. I'm resigning myself to the fact that, if Merrion doesn't know of a way, there is no way.
Re: Determine whether Graphics object is for a printer
so Merrion's way, or the h'way :)
I think this is the first time i have seen you ask a question even tho it was for your boss...
regards
toe
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
toecutter
so Merrion's way, or the h'way :)
I think this is the first time i have seen you ask a question even tho it was for your boss...
regards
toe
I've asked a few questions in the last four years. In this case, Merrion's the local printing geek so I trust what he says on the subject. ;)
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
toecutter
so Merrion's way, or the h'way :)
I think this is the first time i have seen you ask a question even tho it was for your boss...
regards
toe
Normally this happens at some times. I have seen he asked one question in Asp.net Forums..;)
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
toecutter
so Merrion's way, or the h'way :)
I think this is the first time i have seen you ask a question even tho it was for your boss...
regards
toe
I know, I've seen him jumping around answering everyone's questions. Has even helped me out immensely. I would love to be of assistance, although I'm no help. I would have suggested creating a class that inherits graphics, but it seems Graphics cant be inherited, as stated by Pradeep above. Other than the flag thing you mentioned earlier, I see nothing. Sorry. :(
Re: Determine whether Graphics object is for a printer
hehe.. me too :D
If you click on his name and look for "All Posts started by jmclihinney" you would hardly see anything other than threads in the codebanks. ;)
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
jmcilhinney
I've asked a few questions in the last four years. In this case, Merrion's the local printing geek so I trust what he says on the subject. ;)
So maybe 0.000001 % would be a question :)
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
toecutter
So maybe 0.000001 % would be a question :)
No.. It would be much lesser than this :thumb:
Re: Determine whether Graphics object is for a printer
I just counted about 20 threads I've started to ask my own questions going back to June 2005. You see what reading the documentation can do for you? ;) :lol:
Re: Determine whether Graphics object is for a printer
20 questions?? What a nuisance! ffffttt. lol I think I've had 20questions in the last 10 minutes!
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
MundoDragon
20 questions?? What a nuisance! ffffttt. lol I think I've had 20questions in the last 10 minutes!
:lol:
So now go by his suggestion. Pickup some good book/ebook and start reading. :)
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
jmcilhinney
I just counted about 20 threads I've started
Dam, i hope the mods don't read this as they may give you a bill for abusing the free help here :D
Re: Determine whether Graphics object is for a printer
Quote:
Originally Posted by
Pradeep1210
:lol:
So now go by his suggestion. Pickup some good book/ebook and start reading. :)
First of all, I cannot begin to go into the number of books, tutorials and documentations I have read on programming since clear back to my first Basic and QBasic programs. They have to number in the hundreds, but I'd be more apt to say thousands. And I still find nothing that equivalates to simply asking someone one on one. You simply can't say to a book, or documentation, 'Yeah, I see your point there, but although useful, that's not exactly what I'm trying to accomplish.' I find most books tend to give the SAME examples and go over the SAME issues, but are almost never relevent to what I am trying to acheive. I am in no way saying that reading documentation or books is no good, as I always do and will continue to, because usually I will stumble across something that will later be very useful.. I am merely saying they don't usually help me with a very specific problem I am having at the time. Second thing I would like to add is that if jmcilhinney ever writes a book, I will be at the book stand on opening day! Thanks for listening to my rant. :)