Results 1 to 7 of 7

Thread: [RESOLVED] Clipping a shape in a printout

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Resolved [RESOLVED] Clipping a shape in a printout

    In a form I have a picturebox which contains a circular shape placed at a position resulting from some calculation, usually at or near the center, but sometimes it comes out too offset from the center that part of it is clipped as in these figures:

    Name:  circle1.png
Views: 253
Size:  585 BytesName:  circle2.png
Views: 225
Size:  466 Bytes

    Now I have made a printing function where a rectangle is printed representing the border of the picturebox and I use the circle method to draw the circle inside. When the circle is clipped in the picturebox as in the right figure part of the circle comes out of the rectangle and overlaps other information printed at the sides.

    What would be a way around so that the circle came out clipped by the rectangle?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Clipping a shape in a printout

    if the circle is correct in the picturebox, why not print the picturebox, instead of drawing again to the printer?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Clipping a shape in a printout

    Have you tried using a clipping region on the Printer's DC? Something like this?

    Code:
    Option Explicit
    
    Private Sub cmdPrint_Click()
        Form2.Show vbModal, Me
        If Form2.Cancelled Then Exit Sub
        Set Printer = Form2.SelectedPrinter
    
        With Printer
            '8.5 x 11.
            .PaperSize = vbPRPSLetter
            .Orientation = vbPRORPortrait
            .PrintQuality = HighestQuality()
            .ScaleMode = vbInches
    
            .DrawWidth = 4
            .FillStyle = vbFSTransparent
            Printer.Line (2.25, 2)-(6.25, 6), vbBlue, B
    
            SetClipRect 2.25, 2, 6.25, 6, 4
            .DrawWidth = 10
            .FillStyle = vbFSSolid
            .FillColor = &HC0C0C0 'Gray.
            Printer.Circle (5.4, 5.3), 1, vbRed
            ClearClipRect
    
            .EndDoc
        End With
    End Sub
    Name:  sshot.png
Views: 174
Size:  2.1 KB

    The graphics gods here could probably suggest something cleaner though.
    Attached Files Attached Files
    Last edited by dilettante; Mar 29th, 2015 at 07:56 PM. Reason: reposted attachment, was maybe 1 px off

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Clipping a shape in a printout

    Version that prints some text as well (attached).
    Attached Files Attached Files

  5. #5

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Clipping a shape in a printout

    Quote Originally Posted by dilettante View Post
    Version that prints some text as well (attached).
    This looks good, thank you!
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  6. #6

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Clipping a shape in a printout

    Quote Originally Posted by westconn1 View Post
    if the circle is correct in the picturebox, why not print the picturebox, instead of drawing again to the printer?
    Since in the printer the size must be different I tried Stretchblt but it didn't look nice.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [RESOLVED] Clipping a shape in a printout

    Glad it looks like or at least suggests a possible solution. I just went for a walk in the GDI section of the MSDN Library CDs and that's what I came up with.

    There may well be a better approach but someone with more graphics background will have to suggest it. I didn't find anything in the VB6 parts of the documentation for doing this with decent results.

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