2 Attachment(s)
[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:
Attachment 125161Attachment 125163
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?
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?
2 Attachment(s)
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
The graphics gods here could probably suggest something cleaner though.
1 Attachment(s)
Re: Clipping a shape in a printout
Version that prints some text as well (attached).
Re: Clipping a shape in a printout
Quote:
Originally Posted by
dilettante
Version that prints some text as well (attached).
This looks good, thank you!
Re: Clipping a shape in a printout
Quote:
Originally Posted by
westconn1
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.
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.