Jonathan Pobst wrote:
Does the attached patch fix the issue for you?

Well, partially.

The height is determined correctly, but there's still extra decoration to the left and right of the hosted item as demonstrated on attached screenshot.

Like your first email says, we need to figure out why that 68 is there. It is a crutch to support the common case, but it messes up less common cases like this.

While your patch works around the issue, its not the correct solution. This 68 needs to be dynamically calculated from something, whether its margins or paddings or preferred sizes of MenuItems.

I will try to look at this some this week if you don't want to dig any deeper.

Hi,

Thanks for your responses!

Apparently, .NET ToolStripDropDown behaves differently when it's hosted inside ToolStrip and when it's used standalone.

I'm attaching a sample .cs and a PNG screenshot to demonstrate the difference.

So possibly, the correct solution would be to introduce some flag that indicates the drop down is used standalone (or determine this from the existing data like missing Owner, etc.) and adjust layout and painting accordingly.

--
Alex

<<inline: tsdd-toolstrip-and-standalone-dotnet-mono.png>>

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace popup
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }

    public class PopupMenu : ToolStripDropDown
    {
        public PopupMenu()
        {
            this.Items.Add("label1");
        }
    }

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

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

        #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()
        {
            //System.ComponentModel.ComponentResourceManager resources = new 
System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.toolStripDropDownButton1 = new 
System.Windows.Forms.ToolStripDropDownButton();
            this.label1ToolStripMenuItem = new 
System.Windows.Forms.ToolStripMenuItem();
            this.toolStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // toolStrip1
            // 
            this.toolStrip1.Items.AddRange(new 
System.Windows.Forms.ToolStripItem[] {
            this.toolStripDropDownButton1});
            this.toolStrip1.Location = new System.Drawing.Point(0, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(292, 25);
            this.toolStrip1.TabIndex = 0;
            this.toolStrip1.Text = "toolStrip1";
            // 
            // toolStripDropDownButton1
            // 
            this.toolStripDropDownButton1.DisplayStyle = 
System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripDropDownButton1.DropDownItems.AddRange(new 
System.Windows.Forms.ToolStripItem[] {
            this.label1ToolStripMenuItem});
            //this.toolStripDropDownButton1.Image = 
((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image")));
            this.toolStripDropDownButton1.ImageTransparentColor = 
System.Drawing.Color.Magenta;
            this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
            this.toolStripDropDownButton1.Size = new System.Drawing.Size(29, 
22);
            this.toolStripDropDownButton1.Text = "toolStripDropDownButton1";
            // 
            // label1ToolStripMenuItem
            // 
            this.label1ToolStripMenuItem.Name = "label1ToolStripMenuItem";
            this.label1ToolStripMenuItem.Size = new System.Drawing.Size(152, 
22);
            this.label1ToolStripMenuItem.Text = "label1";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.toolStrip1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();
        }
        #endregion

        private System.Windows.Forms.ToolStrip toolStrip1;
        private System.Windows.Forms.ToolStripDropDownButton 
toolStripDropDownButton1;
        private System.Windows.Forms.ToolStripMenuItem label1ToolStripMenuItem;
    }
}
_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Reply via email to