Results 1 to 21 of 21

Thread: Determine whether Graphics object is for a printer

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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?

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    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.

  3. #3

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by Merrion View Post
    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.

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Determine whether Graphics object is for a printer

    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by Pradeep1210 View Post
    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.

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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:
    1. Private Sub MyGraphicsMethod(ByVal g As Graphics, Optional ByVal targetDevice As String = "")
    2.     Select Case targetDevice.ToLower
    3.         Case "printer"
    4.  
    5.         Case Else
    6.  
    7.     End Select
    8. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    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."

  8. #8
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    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.

  9. #9

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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.

  10. #10
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    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

  11. #11

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by toecutter View Post
    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.

  12. #12
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by toecutter View Post
    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

  13. #13
    Addicted Member
    Join Date
    Dec 2002
    Posts
    167

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by toecutter View Post
    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.

  14. #14
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  15. #15
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by jmcilhinney View Post
    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

  16. #16
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by toecutter View Post
    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

  17. #17

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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?

  18. #18
    Addicted Member
    Join Date
    Dec 2002
    Posts
    167

    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.

  19. #19
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by MundoDragon View Post
    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  20. #20
    Frenzied Member toecutter's Avatar
    Join Date
    Apr 2006
    Location
    Brisbane, Australia
    Posts
    1,160

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by jmcilhinney View Post
    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

  21. #21
    Addicted Member
    Join Date
    Dec 2002
    Posts
    167

    Re: Determine whether Graphics object is for a printer

    Quote Originally Posted by Pradeep1210 View Post


    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
  •  



Click Here to Expand Forum to Full Width