HighTechTalks DotNet Forums  

Clipping problem

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Clipping problem in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
MartinParenteau1963@hotmail.com
 
Posts: n/a

Default Clipping problem - 03-22-2007 , 08:57 PM






Hi,

I found something like a bug with clipping in a Windows form. While
creating a billiards game program, I found that drawing directly on
the graphics object is much faster than invalidating the area and
forcing the update (3 ms instead of 15 ms). In order to avoid flicker,
I set a clipping region. Everything seemed to be fine except for one
"small" problem...

For some positions of the clipping rectangle, there seems to be a
difference between what is clipped when painting a rectangle and what
is clipped when drawing a line, especially at the right and bottom
edges of the clipping rectangle. The line can be clipped for a pixel
position where the filling is not clipped. Instead of trying to
explain in detail, here is a very simple code that shows the problem.
While running the program, click once in the client area. You will see
that the lines are clipped. If the lines labelled as "Problem" in the
code are commented out and the lines with "No problem" are compiled
instead, there is not clipping problem.

Has this problem been reported? I can probably do something to work
around it but I assume that it is really a bug. And I can say that
when I use the normal Invalidate/Update technique for specific
rectangles, I don't have that problem.

Thanks!

MartinP

--------------------------------

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

public partial class ClippingForm : Form
{
private Brush m_BackBrush;

public static void Main()
{
Application.Run(new ClippingForm());
}

public ClippingForm()
{
ResizeRedraw = true;
this.Width = 200;
this.Height = 200;
m_BackBrush = Brushes.Yellow;
}

private void DrawForm(Graphics gfx)
{
Pen p = Pens.Teal;
gfx.FillRectangle(m_BackBrush, 0.0F, 0.0F, ClientSize.Width,
ClientSize.Height);

gfx.DrawLine(p, 150.45F, 0.0F, 150.45F, ClientSize.Height); //
Problem
gfx.DrawLine(p, 0.00F, 124.45F, ClientSize.Width, 124.45F); //
Problem

// gfx.DrawLine(p, 150.35F, 0.0F, 150.35F, ClientSize.Height); //
No problem
// gfx.DrawLine(p, 0.00F, 124.35F, ClientSize.Width, 124.35F); //
No problem
}

protected override void OnPaint(System.Windows.Forms.PaintEventArgs
e)
{
DrawForm(e.Graphics);
}

protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
m_BackBrush = Brushes.Orange;
Graphics gfx = CreateGraphics();
gfx.SetClip(new RectangleF(51.0F, 75.0F, 100.0F, 50.0F));
DrawForm(gfx);
gfx.Dispose();
}
}


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.