当前位置: 首页>>代码示例>>C#>>正文


C# ToolStripButton.GetPreferredSize方法代码示例

本文整理汇总了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;
//.........这里部分代码省略.........
开发者ID:nlhepler,项目名称:mono,代码行数:101,代码来源:ToolStripButtonTest.cs


注:本文中的System.Windows.Forms.ToolStripButton.GetPreferredSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。