Jonathan Pobst wrote:
I committed the less risky parts of this, hopefully it will fix your issues.

Hi,

It's me again.


Thanks for your support last time!  However, my issue is not resolved yet...

I've tried your patch on Mac OS and it works correctly there too. But there's another problem: when trying to resize the control displayed in the drop down, the popup window is first moved some pixels down. This is unwanted behavior.

This happens only on Mac OS and not on Linux or Windows.

A minimal sample file to demonstrate this is attached. On test run I get the output like to this:

OnMouseDown: _dropDown.Bounds={X=543,Y=421,Width=102,Height=107}
OnMouseMove: _dropDown.Bounds={X=543,Y=421,Width=102,Height=107}
OnMouseMove: _dropDown.Bounds={X=543,Y=421,Width=103,Height=107}
OnMouseMove: _dropDown.Bounds={X=543,Y=421,Width=104,Height=85}
OnMouseMove: _dropDown.Bounds={X=543,Y=421,Width=105,Height=85}
OnMouseMove: _dropDown.Bounds={X=543,Y=421,Width=106,Height=85}
...

Note the 22 pixels difference between 107 and 85, probably it's a trace of _that_ 22 hardcoded in ToolStripDropDown.OnLayout. :)

The reported location of drop down isn't changed, but I _do_ see it's first moved down on first move, then on second mouse move it gets resized by the event handler, so this puzzles me.

Unfortunately, I cannot grab the screenshots for this issue on Mac due to it's Grab program limitations. I can draw a sketch of what I see if this helps.

Thanks again for your patience with me; looking forward for your feedback!

--
Regards,
Alex


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

namespace popup
{
	public class MyDropDown : UserControl
	{
		public MyDropDown()
		{
			this.Size = new Size(100, 100);
		}
		
		public void Show(Point location)
		{
            ToolStripControlHost host = new ToolStripControlHost(this);
            _dropDown = new ToolStripDropDown();
            _dropDown.Items.Add(host);
            _dropDown.Show(location);
		}

		public override Size GetPreferredSize(Size proposedSize)
		{
			return this.Size;
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);
			
			using (Brush b = new SolidBrush(Color.DarkBlue))
			{
				e.Graphics.FillRectangle(b, this.Bounds);
			}
			// Hilite bottom right corner.
			using (Brush b = new SolidBrush(Color.Blue))
			{
				e.Graphics.FillRectangle(b, Rectangle.FromLTRB(this.Right - 16, this.Bottom - 16,
					this.Right, this.Bottom));
			}
		}

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

			// Check bottom right corner.
            if (e.X >= this.Width - 16 && e.Y >= this.Height - 16)
            {
            	Console.WriteLine("OnMouseDown: _dropDown.Bounds={0}", _dropDown.Bounds);
            	
                _resizeOrigin = e.Location;
                _resizeSize = Size;
                _resizing = true;
            }
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (_resizing)
            {
            	Console.WriteLine("OnMouseMove: _dropDown.Bounds={0}", _dropDown.Bounds);
            	
				this.Size = new Size(_resizeSize.Width + e.X - _resizeOrigin.X,
					_resizeSize.Height + e.Y - _resizeOrigin.Y);
                this.Invalidate();
            }
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (_resizing)
            {
                _resizing = false;
            }
        }
		
		private ToolStripDropDown _dropDown;
		private bool _resizing;
		private Size _resizeSize;
		private Point _resizeOrigin;
	};

    public partial class Form1 : Form
    {
        public Form1()
        {
            this.CenterToScreen();
            this.MouseClick += new MouseEventHandler(Form1_MouseClick);
        }

        void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
				MyDropDown myDropDown = new MyDropDown();
                myDropDown.Show(Point.Add(this.Location, new Size(e.X, e.Y)));
            }
        }
    }

    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}
_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Reply via email to