2

I want to put some images into a ToolStripButton, and have the images change depending on the state of the button.

So I've set the .ImageList of the ToolStrip to be my ImageList and simply change the ToolStripButton.ImageIndex to the appropriate value.

However, the icons appear distorted in comparison to providing exactly the same picture directly to the ToolStripButton.Image property.

In the picture below the image on the left hand side is the one from the ImageList, the one on the right is being set through ToolStripButton.Image. As you can see, the one on the left has some small odd pixels, specially visible when the button is selected.

I've tried modifying the TransparencyColor and ColorDepth but that's not made any difference. Any clues as to what I'm missing?

Odd icons

JohnUbuntu
  • 699
  • 6
  • 19

2 Answers2

1

Try setting AutoSize to false and ImageScaling to ToolStripItemImageScaling.None.

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
0

You can put pictures in Resources and replace ImageList with Dictionary? In this case, pictures will be equal to the original.

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

P.S. Code is in VB.NET but you'll get the point.

CodeCatia
  • 127
  • 1
  • 9