本文整理汇总了C#中System.Windows.Forms.ToolStripButton.GetPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:C# ToolStripButton.GetPreferredSize方法的具体用法?C# ToolStripButton.GetPreferredSize怎么用?C# ToolStripButton.GetPreferredSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ToolStripButton
的用法示例。
在下文中一共展示了ToolStripButton.GetPreferredSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BehaviorAutoSize
[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;
//.........这里部分代码省略.........