【问题标题】:Distorted images when using ImageList on ToolStripButton在 ToolStripButton 上使用 ImageList 时图像失真
【发布时间】:2016-02-29 22:19:23
【问题描述】:

我想将一些图像放入ToolStripButton,并根据按钮的状态更改图像。

所以我将ToolStrip 的.ImageList 设置为我的ImageList,并将ToolStripButton.ImageIndex 更改为适当的值。

但是,与直接向ToolStripButton.Image 属性提供完全相同的图片相比,这些图标显得有些失真。

在下图中,左边的图片是来自ImageList的图片,右边的图片是通过ToolStripButton.Image设置的。如您所见,左边的有一些小的奇数像素,在选择按钮时特别可见。

我尝试修改 TransparencyColor 和 ColorDepth 但这并没有什么区别。关于我缺少什么的任何线索?

【问题讨论】:

    标签: c# .net toolstrip toolstripbutton


    【解决方案1】:

    尝试将AutoSize 设置为false 并将ImageScaling 设置为ToolStripItemImageScaling.None。

    【讨论】:

    • 感谢您的建议,但都没有用。
    【解决方案2】:

    你可以把图片放到资源里,把ImageList换成Dictionary?在这种情况下,图片将与原始图片相同。

    Dim dictPictures As New Dictionary(Of String, Bitmap)
    Dim runTimeResourceSet As Object
    Dim dictEntry As DictionaryEntry
    runTimeResourceSet = My.Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, True, True)
    For Each dictEntry In runTimeResourceSet
        If (dictEntry.Value.GetType() Is GetType(Bitmap)) Then
            If Not dictPictures.ContainsKey(dictEntry.Key & ".png") Then dictPictures.Add(dictEntry.Key & ".png", dictEntry.Value)
        End If
    Next
    

    附:代码在VB.NET,但你会明白的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-10
      • 1970-01-01
      相关资源
      最近更新 更多