ToolStripItemImageScaling 枚举

定义

指定 ToolStripItem 上的图像的大小是否自动调整为适合 ToolStrip 的大小,并同时保持原始图像的比例。

C#
public enum ToolStripItemImageScaling
继承
ToolStripItemImageScaling

字段

None 0

指定 ToolStripItem 上的图像的大小不自动调整为适合 ToolStrip 的大小。

SizeToFit 1

指定 ToolStripItem 上的图像的大小自动调整为适合 ToolStrip 的大小。

示例

以下示例将 ToolStripItem.ImageScaling 属性设置为 SizeToFit.

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);
}

注解

ImageAlignImageImageIndexImageKeyImageScaling属性与图像处理的各个方面有关。 通过直接设置这些属性或设置仅ImageList运行时属性,在控件中使用ToolStrip图像。

图像缩放由两者ToolStripToolStripItem中的属性交互决定,如下所示:

  • ImageScalingSize 是最终映像的规模,由映像 ImageScaling 设置和容器 AutoSize 设置的组合决定。

    • true 如果AutoSize (默认) 且ToolStripItemImageScaling``SizeToFit不发生图像缩放,并且ToolStrip大小为最大项或规定的最小大小。

    • 如果是AutoSizeToolStripItemImageScaling不是None,则不会发生图像和ToolStrip缩放。false

若要控制图像大小,请使用 ImageScalingSize 该属性。

适用于

产品 版本
.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
Windows Desktop 3.0, 3.1, 5, 6, 7