[Mono-winforms-list] 1 pixel offset problem

mzyzik at gmail.com mzyzik at gmail.com
Sat Jul 26 18:35:06 EDT 2008


On Thu, Jul 24, 2008 at 11:57:12AM -0300, Ernesto wrote:
> 
> Hi,
> 
> I noticed that System.Drawing primitives will sometimes render things 
> with a one pixel offset. I noticed that this affects MWF too, and I 
> understand this is a libgdi problem, probably related to the fact that 
> cairo takes pixel coordinates in a different way than Windows' GDI+.
> The attached screenshot shows the problem in the Cancel button right 
> border of a MessageBox.
> 
> I'm willing to try to fix this, but I wanted to ask first if this is a 
> known issue or limitation of the current gdiplus implementation.
> 
> Regards,
> Ernesto
> 

I see another potentially related bug with drawing. I am trying to draw
some Bezier curves (with GraphicsPath); and the positioning and
appearance is way off (at least with respect to MS .NET).

Can someone comment on this? I have attached source code, makefile, and
two screenshots (ms.net/windows vs. mono/linux).

I am on Mono 1.9 and libgdiplus 1.9

--Matt
-------------- next part --------------
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace SWFTest
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.LinkLabel linkLabel1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.TextBox textBox1;
		private System.ComponentModel.IContainer components;

		LinearGradientBrush lgb;
		GraphicsPath path;
		Pen pFS;
		int dX = 520;
		int dY = 320;
		int cirSize = 152;

		public Form1()
		{
			pFS = new Pen(Color.Blue, 16);
			lgb = new LinearGradientBrush(new Point(0,dY), new Point(0,dY+118), Color.FromArgb(160, Color.Blue), Color.Green);
			path = new GraphicsPath(new Point[]
								{
									new Point(dX-64, dY-24),//start
									new Point(dX-59, dY-34),//focal point 1
									new Point(dX-52, dY-54),//focal point 2
									new Point(dX-18, dY-66),//top
									new Point(dX-34, dY-47),//focal point 1
									new Point(dX-43, dY-27),//focal point 2
									new Point(dX-44, dY-8),//end
			}, new byte[]
								{
									(byte)PathPointType.Start,
									(byte)PathPointType.Bezier,
									(byte)PathPointType.Bezier,
									(byte)PathPointType.Bezier,
									(byte)PathPointType.Bezier,
									(byte)PathPointType.Bezier,
									(byte)PathPointType.Bezier,
			});

			InitializeComponent();

			this.SetStyle(ControlStyles.UserPaint, true);
			this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			//draw the plus
			e.Graphics.DrawLine(pFS, dX-100, dY, dX+100, dY);
			e.Graphics.DrawLine(pFS, dX, dY-100, dX, dY+100);

			//draw circle
			e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
			e.Graphics.DrawEllipse(pFS, dX-(cirSize/2), dY-(cirSize/2), cirSize, cirSize);

			//draw the gradient
			e.Graphics.FillPath(lgb, path);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.label1 = new System.Windows.Forms.Label();
			this.linkLabel1 = new System.Windows.Forms.LinkLabel();
			this.button1 = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			//
			// label1
			//
			this.label1.Location = new System.Drawing.Point(111, 252);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "label1";
			//
			// linkLabel1
			//
			this.linkLabel1.Location = new System.Drawing.Point(26, 74);
			this.linkLabel1.Name = "linkLabel1";
			this.linkLabel1.TabIndex = 1;
			this.linkLabel1.TabStop = true;
			this.linkLabel1.Text = "linkLabel1";
			//
			// button1
			//
			this.button1.Location = new System.Drawing.Point(26, 117);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "button1";
			this.button1.Click += new EventHandler(ohye);
			//
			// textBox1
			//
			this.textBox1.Location = new System.Drawing.Point(17, 157);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 3;
			this.textBox1.Text = "textBox1";
			//
			//
			//
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(613, 570);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.linkLabel1);
			this.Controls.Add(this.label1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		void ohye(object asdf, EventArgs fwe)
		{
			MessageBox.Show("yeah");
		}

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main()
		{
			Application.Run(new Form1());
		}
	}
}
-------------- next part --------------
all:
	mcs /r:System.Windows.Forms.dll /r:System.Drawing.dll /r:System.Data.dll /target:exe /out:aa.exe Form1.cs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: win.png
Type: image/png
Size: 20305 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20080726/71d57b46/attachment-0002.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lin.png
Type: image/png
Size: 19267 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20080726/71d57b46/attachment-0003.png 


More information about the Mono-winforms-list mailing list