Ejemplo n.º 1
0
            private void LayoutButton(ToolStripButton button)
            {
                Size size = button.GetPreferredSize(_displayRectangle.Size);

                size.Height = TabSize.Height;

                LayoutItem(button, size, true);
            }
        [NUnit.Framework.Category("NotWorking")] // Font dependent, values are for win32
        public void BehaviorAutoSize()
        {
            // Lots of things depend on this, it needs to be 100% correct...
            ToolStripItem tsi = new ToolStripButton();

            string string1      = "ABCDEFG";
            string string2      = "qwertyuiop--123456";
            Font   f1           = tsi.Font;
            Font   f2           = new Font("Arial", 14);
            Size   string1size  = TextRenderer.MeasureText(string1, f1);
            Size   string2size  = TextRenderer.MeasureText(string2, f1);
            Size   string1size2 = TextRenderer.MeasureText(string1, f2);
            Size   string2size2 = TextRenderer.MeasureText(string2, f2);
            Image  i            = new Bitmap(16, 16);
            Image  i2           = new Bitmap(22, 22);

            Assert.AreEqual(new Size(23, 4), tsi.GetPreferredSize(Size.Empty), "K1");

            // Text only
            tsi.Text = string1;
            Assert.AreEqual(new Size(string1size.Width + 4, string1size.Height + 4), tsi.GetPreferredSize(Size.Empty), "K2");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size.Width + 4, string1size.Height + 4), tsi.GetPreferredSize(Size.Empty), "K3");

            tsi.Font = f2;
            tsi.Text = string1;
            Assert.AreEqual(new Size(string1size2.Width + 4, string1size2.Height + 4), tsi.GetPreferredSize(Size.Empty), "K4");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size2.Width + 4, string1size2.Height + 4), tsi.GetPreferredSize(Size.Empty), "K5");

            // Text and image
            tsi.Image = i;
            tsi.Font  = f1;
            tsi.Text  = string1;
            Assert.AreEqual(new Size(string1size.Width + 20, string1size.Height + 7), tsi.GetPreferredSize(Size.Empty), "K6");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size.Width + 20, string2size.Height + 7), tsi.GetPreferredSize(Size.Empty), "K7");

            tsi.Image = i2;
            tsi.Font  = f2;
            tsi.Text  = string1;
            Assert.AreEqual(new Size(string1size2.Width + 26, Math.Max(string1size2.Height + 4, 26)), tsi.GetPreferredSize(Size.Empty), "K8");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size2.Width + 26, Math.Max(string1size2.Height + 4, 26)), tsi.GetPreferredSize(Size.Empty), "K9");

            // Image only
            tsi.Image = i;
            tsi.Text  = string.Empty;

            Assert.AreEqual(new Size(23, 20), tsi.GetPreferredSize(Size.Empty), "K10");

            tsi.Image = i2;
            Assert.AreEqual(new Size(26, 26), tsi.GetPreferredSize(Size.Empty), "K11");

            // DisplayStyle = text
            tsi.Image        = null;
            tsi.Text         = string1;
            tsi.Font         = f1;
            tsi.DisplayStyle = ToolStripItemDisplayStyle.Text;

            Assert.AreEqual(new Size(string1size.Width + 4, string1size.Height + 4), tsi.GetPreferredSize(Size.Empty), "K12");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size.Width + 4, string1size.Height + 4), tsi.GetPreferredSize(Size.Empty), "K13");

            tsi.Font = f2;
            tsi.Text = string1;
            Assert.AreEqual(new Size(string1size2.Width + 4, string1size2.Height + 4), tsi.GetPreferredSize(Size.Empty), "K14");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size2.Width + 4, string1size2.Height + 4), tsi.GetPreferredSize(Size.Empty), "K15");

            // DisplayStyle = image
            tsi.Image        = i;
            tsi.Text         = string.Empty;
            tsi.DisplayStyle = ToolStripItemDisplayStyle.Image;

            Assert.AreEqual(new Size(23, 20), tsi.GetPreferredSize(Size.Empty), "K16");

            tsi.Image = i2;
            Assert.AreEqual(new Size(26, 26), tsi.GetPreferredSize(Size.Empty), "K17");

            // DisplayStyle = textandimage, imagebeforetext
            tsi.Image        = i;
            tsi.Font         = f1;
            tsi.Text         = string1;
            tsi.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
            Assert.AreEqual(new Size(string1size.Width + 20, 20), tsi.GetPreferredSize(Size.Empty), "K18");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size.Width + 20, 20), tsi.GetPreferredSize(Size.Empty), "K19");

            tsi.Image = i2;
            tsi.Font  = f2;
            tsi.Text  = string1;
            Assert.AreEqual(new Size(string1size2.Width + 26, Math.Max(string1size2.Height + 4, 26)), tsi.GetPreferredSize(Size.Empty), "K20");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size2.Width + 26, Math.Max(string1size2.Height + 4, 26)), tsi.GetPreferredSize(Size.Empty), "K21");

            // DisplayStyle = textandimage, TextBeforeImage
            tsi.Image             = i;
            tsi.Font              = f1;
            tsi.Text              = string1;
            tsi.TextImageRelation = TextImageRelation.TextBeforeImage;
            Assert.AreEqual(new Size(string1size.Width + 20, 20), tsi.GetPreferredSize(Size.Empty), "K22");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size.Width + 20, 20), tsi.GetPreferredSize(Size.Empty), "K23");

            tsi.Image = i2;
            tsi.Font  = f2;
            tsi.Text  = string1;
            Assert.AreEqual(new Size(string1size2.Width + 26, Math.Max(string1size2.Height + 4, 26)), tsi.GetPreferredSize(Size.Empty), "K24");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size2.Width + 26, Math.Max(string1size2.Height + 4, 26)), tsi.GetPreferredSize(Size.Empty), "K25");

            // DisplayStyle = textandimage, overlay
            tsi.Image             = i;
            tsi.Font              = f1;
            tsi.Text              = string1;
            tsi.TextImageRelation = TextImageRelation.Overlay;
            Assert.AreEqual(new Size(string1size.Width + 4, 20), tsi.GetPreferredSize(Size.Empty), "K26");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size.Width + 4, 20), tsi.GetPreferredSize(Size.Empty), "K27");

            tsi.Image = i2;
            tsi.Font  = f2;
            tsi.Text  = string1;
            Assert.AreEqual(new Size(string1size2.Width + 4, Math.Max(string1size2.Height + 4, 26)), tsi.GetPreferredSize(Size.Empty), "K28");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size2.Width + 4, Math.Max(string1size2.Height + 4, 26)), tsi.GetPreferredSize(Size.Empty), "K29");

            // DisplayStyle = textandimage, TextAboveImage
            tsi.Image             = i;
            tsi.Font              = f1;
            tsi.Text              = string1;
            tsi.TextImageRelation = TextImageRelation.TextAboveImage;
            Assert.AreEqual(new Size(string1size.Width + 4, string1size.Height + tsi.Image.Height + 4), tsi.GetPreferredSize(Size.Empty), "K30");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size.Width + 4, string2size.Height + tsi.Image.Height + 4), tsi.GetPreferredSize(Size.Empty), "K31");

            tsi.Image = i2;
            tsi.Font  = f2;
            tsi.Text  = string1;
            Assert.AreEqual(new Size(string1size2.Width + 4, string1size2.Height + tsi.Image.Height + 4), tsi.GetPreferredSize(Size.Empty), "K32");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size2.Width + 4, string2size2.Height + tsi.Image.Height + 4), tsi.GetPreferredSize(Size.Empty), "K33");

            // DisplayStyle = textandimage, ImageAboveText
            tsi.Image             = i;
            tsi.Font              = f1;
            tsi.Text              = string1;
            tsi.TextImageRelation = TextImageRelation.ImageAboveText;
            Assert.AreEqual(new Size(string1size.Width + 4, string1size.Height + tsi.Image.Height + 4), tsi.GetPreferredSize(Size.Empty), "K34");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size.Width + 4, string2size.Height + tsi.Image.Height + 4), tsi.GetPreferredSize(Size.Empty), "K35");

            tsi.Image = i2;
            tsi.Font  = f2;
            tsi.Text  = string1;
            Assert.AreEqual(new Size(string1size2.Width + 4, string1size2.Height + tsi.Image.Height + 4), tsi.GetPreferredSize(Size.Empty), "K36");

            tsi.Text = string2;
            Assert.AreEqual(new Size(string2size2.Width + 4, string2size2.Height + tsi.Image.Height + 4), tsi.GetPreferredSize(Size.Empty), "K37");
        }