本文整理汇总了C#中System.Windows.Forms.ToolStripLabel.GetPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:C# ToolStripLabel.GetPreferredSize方法的具体用法?C# ToolStripLabel.GetPreferredSize怎么用?C# ToolStripLabel.GetPreferredSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ToolStripLabel
的用法示例。
在下文中一共展示了ToolStripLabel.GetPreferredSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HeaderStrip
public HeaderStrip()
{
this.Dock = DockStyle.Top;
this.GripStyle = ToolStripGripStyle.Hidden;
this.AutoSize = false;
// Set renderer - override background painting
SetRenderer();
// Setup Headers
Font font = SystemFonts.MenuFont;
this.Font = new Font("Arial", font.SizeInPoints + 3.75F, FontStyle.Bold);
this.ForeColor = System.Drawing.Color.Gray;
ToolStripLabel tsl = new ToolStripLabel();
tsl.Font = this.Font;
tsl.Text = "I";
this.Height = tsl.GetPreferredSize(Size.Empty).Height + 6;
}
示例2: SetHeaderStyle
private void SetHeaderStyle()
{
// Get system font
Font font = SystemFonts.MenuFont;
if ( _headerStyle == AreaHeaderStyle.Large )
{
Font = new Font( @"Arial", font.SizeInPoints + 3.75F, FontStyle.Bold );
ForeColor = Color.White;
}
else
{
Font = font;
ForeColor = Color.White;
}
// Only way to calculate size
var tsl = new ToolStripLabel {Font = Font, Text = @"I"};
// Set Size
Height = tsl.GetPreferredSize( Size.Empty ).Height + 6;
}
示例3: SetHeaderStyle
private void SetHeaderStyle()
{
// Get system font
Font font = SystemFonts.MenuFont;
if (_headerStyle == AreaHeaderStyle.Large)
{
this.Font = new Font("Arial", font.SizeInPoints + 3.75F, FontStyle.Bold);
this.ForeColor = System.Drawing.Color.White;
}
else
{
this.Font = font;
this.ForeColor = System.Drawing.Color.Black;
}
// Only way to calculate size
ToolStripLabel tsl = new ToolStripLabel();
tsl.Font = this.Font;
tsl.Text = "I";
// Set Size
this.Height = tsl.GetPreferredSize(Size.Empty).Height + 6;
}
示例4: 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 ToolStripLabel ();
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 (0, 0), tsi.GetPreferredSize (Size.Empty), "K1");
// Text only
tsi.Text = string1;
Assert.AreEqual (new Size (string1size.Width, string1size.Height), tsi.GetPreferredSize (Size.Empty), "K2");
tsi.Text = string2;
Assert.AreEqual (new Size (string2size.Width, string1size.Height), tsi.GetPreferredSize (Size.Empty), "K3");
tsi.Font = f2;
tsi.Text = string1;
Assert.AreEqual (new Size (string1size2.Width, string1size2.Height), tsi.GetPreferredSize (Size.Empty), "K4");
tsi.Text = string2;
Assert.AreEqual (new Size (string2size2.Width, string1size2.Height), tsi.GetPreferredSize (Size.Empty), "K5");
// Text and image
tsi.Image = i;
tsi.Font = f1;
tsi.Text = string1;
Assert.AreEqual (new Size (string1size.Width + 16, string1size.Height + 3), tsi.GetPreferredSize (Size.Empty), "K6");
tsi.Text = string2;
Assert.AreEqual (new Size (string2size.Width + 16, string2size.Height + 3), tsi.GetPreferredSize (Size.Empty), "K7");
tsi.Image = i2;
tsi.Font = f2;
tsi.Text = string1;
Assert.AreEqual (new Size (string1size2.Width + 22, Math.Max (string1size2.Height, 22)), tsi.GetPreferredSize (Size.Empty), "K8");
tsi.Text = string2;
Assert.AreEqual (new Size (string2size2.Width + 22, Math.Max (string1size2.Height, 22)), tsi.GetPreferredSize (Size.Empty), "K9");
// Image only
tsi.Image = i;
tsi.Text = string.Empty;
Assert.AreEqual (new Size (16, 16), tsi.GetPreferredSize (Size.Empty), "K10");
tsi.Image = i2;
Assert.AreEqual (new Size (22, 22), 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, string1size.Height), tsi.GetPreferredSize (Size.Empty), "K12");
tsi.Text = string2;
Assert.AreEqual (new Size (string2size.Width, string1size.Height), tsi.GetPreferredSize (Size.Empty), "K13");
tsi.Font = f2;
tsi.Text = string1;
Assert.AreEqual (new Size (string1size2.Width, string1size2.Height), tsi.GetPreferredSize (Size.Empty), "K14");
tsi.Text = string2;
Assert.AreEqual (new Size (string2size2.Width, string1size2.Height), tsi.GetPreferredSize (Size.Empty), "K15");
// DisplayStyle = image
tsi.Image = i;
tsi.Text = string.Empty;
tsi.DisplayStyle = ToolStripItemDisplayStyle.Image;
Assert.AreEqual (new Size (16, 16), tsi.GetPreferredSize (Size.Empty), "K16");
tsi.Image = i2;
Assert.AreEqual (new Size (22, 22), 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 + 16, 16), tsi.GetPreferredSize (Size.Empty), "K18");
tsi.Text = string2;
Assert.AreEqual (new Size (string2size.Width + 16, 16), tsi.GetPreferredSize (Size.Empty), "K19");
tsi.Image = i2;
tsi.Font = f2;
tsi.Text = string1;
//.........这里部分代码省略.........