ToolStripItem.ToolTipText 属性

定义

获取或设置作为控件的 ToolTip 显示的文本。

C#
public string ToolTipText { get; set; }
C#
public string? ToolTipText { get; set; }

属性值

一个表示工具提示文本的字符串。

示例

下面的代码示例演示如何为 ToolStripItem设置 ImageImageScalingImageTransparentColor 。 此外,它还演示如何设置和显示项的自定义工具提示。

C#
internal ToolStripButton imageButton;

private void InitializeImageButtonWithToolTip()
{

    // Construct the button and set the image-related properties.
    imageButton = new ToolStripButton();
    imageButton.Image = new Bitmap(typeof(Timer), "Timer.bmp");
    imageButton.ImageScaling = ToolStripItemImageScaling.SizeToFit;

    // Set the background color of the image to be transparent.
    imageButton.ImageTransparentColor = Color.FromArgb(0, 255, 0);

    // Show ToolTip text, set custom ToolTip text, and turn
    // off the automatic ToolTips.
    toolStrip1.ShowItemToolTips = true;
    imageButton.ToolTipText = "Click for the current time";
    imageButton.AutoToolTip = false;

    // Add the button to the ToolStrip.
    toolStrip1.Items.Add(imageButton);
}

注解

ToolTipText仅当 设置为 trueShowItemToolTips有效。 如果 AutoToolTip 设置为 ,则Text项的 属性用作 ToolTipTexttrue

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10