Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It appears that this is a known bug...</p> <p>The following code appears to function as you requested:</p> <pre><code>protected override void OnPaint(PaintEventArgs e) { PointF[] points = new PointF[] { new PointF(73.36f, 196), new PointF(75.44f, 32), new PointF(77.52f, 32), new PointF(79.6f, 196), new PointF(85.84f, 196) }; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Rectangle b = new Rectangle(70, 32, 20, 165); e.Graphics.SetClip(b); e.Graphics.DrawLines(Pens.Red, points); // clipped incorrectly e.Graphics.TranslateTransform(80, 0); e.Graphics.ResetClip(); e.Graphics.DrawLines(Pens.Red, points); } </code></pre> <p>Note: I have AntiAlias'ed the line and extended your clipping region by 1</p> <p>it appears that the following work arounds might help (although not tested):</p> <ul> <li>The pen is more than one pixel thick</li> <li>The line is perfectly horizontal or vertical</li> <li>The clipping is against the window boundaries rather than a clip rectangle</li> </ul> <p>The following is a list of articles that might / or then again might not help:</p> <p><a href="http://www.tech-archive.net/pdf/Archive/Development/microsoft.public.win32.programmer.gdi/2004-08/0350.pdf" rel="nofollow noreferrer">http://www.tech-archive.net/pdf/Archive/Development/microsoft.public.win32.programmer.gdi/2004-08/0350.pdf</a> <a href="http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.gdi/2004-08/0368.html" rel="nofollow noreferrer">http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.gdi/2004-08/0368.html</a></p> <p>OR...</p> <p>the following is also possible:</p> <pre><code>protected override void OnPaint ( PaintEventArgs e ) { PointF[] points = new PointF[] { new PointF(73.36f, 196), new PointF(75.44f, 32), new PointF(77.52f, 32), new PointF(79.6f, 196), new PointF(85.84f, 196) }; Rectangle b = new Rectangle( 70, 32, 20, 164 ); Region reg = new Region( b ); e.Graphics.SetClip( reg, System.Drawing.Drawing2D.CombineMode.Union); e.Graphics.DrawLines( Pens.Red, points ); // clipped incorrectly e.Graphics.TranslateTransform( 80, 0 ); e.Graphics.ResetClip(); e.Graphics.DrawLines( Pens.Red, points ); } </code></pre> <p>This effecivly clips using a region combined/unioned (I think) with the ClientRectangle of the canvas/Control. As the region is difned from the rectangle, the results should be what is expected. This code can be proven to work by adding</p> <pre><code>e.Graphics.FillRectangle( new SolidBrush( Color.Black ), b ); </code></pre> <p>after the setClip() call. This clearly shows the black rectangle only appearing in the clipped region.</p> <p>This could be a valid workaround if Anti-Aliasing the line is not an option.</p> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload