[Mono-bugs] [Bug 414166] New: UserControl.OnPaint(e.Graphics.Clip) not set if ControlStyles.OptimizedDoubleBuffer
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Sat Aug 2 16:02:13 EDT 2008
https://bugzilla.novell.com/show_bug.cgi?id=414166
Summary: UserControl.OnPaint(e.Graphics.Clip) not set if
ControlStyles.OptimizedDoubleBuffer
Product: Mono: Class Libraries
Version: 2.0
Platform: Other
URL: http://limada.sourceforge.net/Limaki/
OS/Version: Windows XP
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Windows.Forms
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: lytico at users.sourceforge.net
QAContact: mono-bugs at lists.ximian.com
Found By: DeveloperNet
Description of Problem:
if you have an UserControl and set style to OptimizedDoubleBuffer:
on .NET you'll get the following result in OnPaint:
the Region e.Graphics.Clip is set to
Rectangle.Intersect(e.ClipRectangle,this.ClientRectangle)
on mono:
e.Graphics.Clip is infinite
Steps to reproduce the problem:
1. make a UserControl and set OptimizedDoubleBuffer:
2. override OnPaint and trace e.Graphics.ClipBounds
Actual Results:
Invalidate({X=5,Y=5,Width=500,Height=100})
OnPaint ()
this.ClientRectangle {X=0,Y=0,Width=445,Height=262}
g.Clip.GetBounds(g) {X=-4194304,Y=-4194304,Width=8388608,Height=8388608}
g.ClipBounds {X=-4194304,Y=-4194304,Width=8388608,Height=8388608}
e.ClipRectangle {X=5,Y=5,Width=440,Height=100}
Expected Results:
Invalidate({X=5,Y=5,Width=500,Height=100})
OnPaint ()
this.ClientRectangle {X=0,Y=0,Width=445,Height=226}
g.Clip.GetBounds(g) {X=5,Y=5,Width=440,Height=100}
g.ClipBounds {X=5,Y=5,Width=440,Height=100}
e.ClipRectangle {X=5,Y=5,Width=440,Height=100}
How often does this happen?
always
Additional Information:
a workaround (or solution) could be:
. if OptimizedDoubleBuffer
e.Graphics.SetClip(Rectangle.Intersect(e.ClipRectangle,this.ClientRectangle))
Testcase:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace MonoWinformTests {
public class TestRegionAndOnPaint : UserControl {
private Rectangle rect = Rectangle.Empty;
public TestRegionAndOnPaint() {
this.AutoScroll = true;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ControlStyles controlStyle =
ControlStyles.UserPaint
| ControlStyles.AllPaintingInWmPaint
// this enables graphics.Clip and graphics.ClipBounds:
| ControlStyles.OptimizedDoubleBuffer;
this.SetStyle(controlStyle, true);
}
protected override void OnPaint(PaintEventArgs e) {
base.OnPaint(e);
Graphics g = e.Graphics;
Point pt = this.AutoScrollPosition;
g.TranslateTransform(pt.X, pt.Y);
if (rect != Rectangle.Empty) {
g.FillRectangle(SystemBrushes.Window, rect);
}
string s = "OnPaint ()"+
"\nthis.ClientRectangle\t" + this.ClientRectangle +
"\ng.Clip.GetBounds(g)\t" + g.Clip.GetBounds(g) +
"\ng.ClipBounds\t\t" + g.ClipBounds +
"\ne.ClipRectangle\t\t" + e.ClipRectangle;
// workaround:
Region region = new Region();
region.MakeInfinite();
region.Intersect(
Rectangle.Intersect(e.ClipRectangle,this.ClientRectangle));
region.Translate(-pt.X, -pt.Y);
s+= "\nworkaround:\nregion.GetBounds(g)\t" + region.GetBounds(g);
System.Console.WriteLine(s);
}
public void Execute() {
rect.Location = new Point(5, 5);
rect.Size = new Size(500, 100);
this.AutoScrollMinSize = new Size(rect.Right, rect.Bottom);
this.Invalidate(rect);
System.Console.WriteLine("Invalidate("+rect+")");
}
}
#region Test-Environment
public class TestForm : Form {
public TestForm() {
InitializeComponent();
testRegionAndOnPaint.Execute();
}
private void button1_Click(object sender, EventArgs e) {
this.testRegionAndOnPaint.Execute();
}
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent() {
this.panel1 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.testRegionAndOnPaint = new
MonoWinformTests.TestRegionAndOnPaint();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.button1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(66, 266);
this.panel1.TabIndex = 0;
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Top;
this.button1.Location = new System.Drawing.Point(0, 0);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(66, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Invalidate(rect)";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// testRegionAndOnPaint
//
this.testRegionAndOnPaint.AutoScroll = true;
this.testRegionAndOnPaint.Dock =
System.Windows.Forms.DockStyle.Fill;
this.testRegionAndOnPaint.Location = new System.Drawing.Point(66,
0);
this.testRegionAndOnPaint.Name = "testRegionAndOnPaint";
this.testRegionAndOnPaint.Size = new System.Drawing.Size(300, 200);
this.testRegionAndOnPaint.TabIndex = 1;
//
// TestEnvironmentForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(400, 200);
this.Controls.Add(this.testRegionAndOnPaint);
this.Controls.Add(this.panel1);
this.Name = "TestEnvironmentForm";
this.Text = "Test AutoScroll";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private TestRegionAndOnPaint testRegionAndOnPaint;
}
static class TestProgram {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
}
#endregion
}
cheers,
lytico
on trying to get Limaki.WidgetDisplay to run on mono
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list