本文整理汇总了C#中System.Windows.Forms.DrawToolTipEventArgs.AssociatedControl属性的典型用法代码示例。如果您正苦于以下问题:C# DrawToolTipEventArgs.AssociatedControl属性的具体用法?C# DrawToolTipEventArgs.AssociatedControl怎么用?C# DrawToolTipEventArgs.AssociatedControl使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.DrawToolTipEventArgs
的用法示例。
在下文中一共展示了DrawToolTipEventArgs.AssociatedControl属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: toolTip1_Draw
// Handles drawing the ToolTip.
private void toolTip1_Draw(System.Object sender,
System.Windows.Forms.DrawToolTipEventArgs e)
{
// Draw the ToolTip differently depending on which
// control this ToolTip is for.
// Draw a custom 3D border if the ToolTip is for button1.
if (e.AssociatedControl == button1)
{
// Draw the standard background.
e.DrawBackground();
// Draw the custom border to appear 3-dimensional.
e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] {
new Point (0, e.Bounds.Height - 1),
new Point (0, 0),
new Point (e.Bounds.Width - 1, 0)
});
e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] {
new Point (0, e.Bounds.Height - 1),
new Point (e.Bounds.Width - 1, e.Bounds.Height - 1),
new Point (e.Bounds.Width - 1, 0)
});
// Specify custom text formatting flags.
TextFormatFlags sf = TextFormatFlags.VerticalCenter |
TextFormatFlags.HorizontalCenter |
TextFormatFlags.NoFullWidthCharacterBreak;
// Draw the standard text with customized formatting options.
e.DrawText(sf);
}
// Draw a custom background and text if the ToolTip is for button2.
else if (e.AssociatedControl == button2)
{
// Draw the custom background.
e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);
// Draw the standard border.
e.DrawBorder();
// Draw the custom text.
// The using block will dispose the StringFormat automatically.
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
sf.FormatFlags = StringFormatFlags.NoWrap;
using (Font f = new Font("Tahoma", 9))
{
e.Graphics.DrawString(e.ToolTipText, f,
SystemBrushes.ActiveCaptionText, e.Bounds, sf);
}
}
}
// Draw the ToolTip using default values if the ToolTip is for button3.
else if (e.AssociatedControl == button3)
{
e.DrawBackground();
e.DrawBorder();
e.DrawText();
}
}