-
May 11th, 2009, 02:10 AM
#1
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?
-
May 11th, 2009, 06:03 AM
#2
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.
-
May 11th, 2009, 06:36 AM
#3
Re: Determine whether Graphics object is for a printer
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.
-
May 11th, 2009, 07:11 AM
#4
Re: Determine whether Graphics object is for a printer
-
May 11th, 2009, 08:57 AM
#5
Re: Determine whether Graphics object is for a printer
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.
-
May 11th, 2009, 12:52 PM
#6
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
-
May 11th, 2009, 02:45 PM
#7
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.
"Ok, my response to that is pending a Google search" - Bucky Katt.
"There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
"Before you can 'think outside the box' you need to understand where the box is."
-
May 12th, 2009, 01:40 AM
#8
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.
-
May 12th, 2009, 01:49 AM
#9
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.
-
May 12th, 2009, 01:53 AM
#10
Frenzied Member
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
-
May 12th, 2009, 01:56 AM
#11
Re: Determine whether Graphics object is for a printer
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.
-
May 12th, 2009, 02:01 AM
#12
Re: Determine whether Graphics object is for a printer
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..
Please mark you thread resolved using the Thread Tools as shown
-
May 12th, 2009, 02:01 AM
#13
Addicted Member
Re: Determine whether Graphics object is for a printer
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.
There aren't many problems that ten gallons of gas and a large nose can't cure. Only problem is, most of us don't have ten gallons of gas lying around.
-
May 12th, 2009, 02:02 AM
#14
Re: Determine whether Graphics object is for a printer
hehe.. me too
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.
-
May 12th, 2009, 02:03 AM
#15
Frenzied Member
Re: Determine whether Graphics object is for a printer
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
-
May 12th, 2009, 02:05 AM
#16
Re: Determine whether Graphics object is for a printer
Originally Posted by toecutter
So maybe 0.000001 % would be a question
No.. It would be much lesser than this
Please mark you thread resolved using the Thread Tools as shown
-
May 12th, 2009, 02:12 AM
#17
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?
-
May 12th, 2009, 02:22 AM
#18
Addicted Member
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!
There aren't many problems that ten gallons of gas and a large nose can't cure. Only problem is, most of us don't have ten gallons of gas lying around.
-
May 12th, 2009, 02:27 AM
#19
Re: Determine whether Graphics object is for a printer
Originally Posted by MundoDragon
20 questions?? What a nuisance! ffffttt. lol I think I've had 20questions in the last 10 minutes!
So now go by his suggestion. Pickup some good book/ebook and start reading.
-
May 12th, 2009, 02:28 AM
#20
Frenzied Member
Re: Determine whether Graphics object is for a printer
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
-
May 12th, 2009, 05:24 AM
#21
Addicted Member
Re: Determine whether Graphics object is for a printer
Originally Posted by Pradeep1210
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.
There aren't many problems that ten gallons of gas and a large nose can't cure. Only problem is, most of us don't have ten gallons of gas lying around.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|