1

ToolStrip アイテムの画像をフィット/サイズ変更する方法はありますか? 私はすでにプロパティを設定していますAutoSize = FalseImageScaling = SizeToFitSize = 40, 40アイテムのボックスのみがサイズ変更され(画像の周りにスペースを残します)、画像のサイズはデフォルトのサイズのままです。

次に、Image に挿入するのではなく、BackgroundImage を使用して画像を挿入することにしました。画像に合わせたりサイズを変更したりできますが、システムを実行して ToolStrip アイテムにカーソルを合わせると、アイテムの画像が消えるという問題があります。このソリューションResizing ToolStripButtons to fit complete BackGround imageを見つけましたが、使用して適用する方法がわかりませんvb.net

親切に私を助けてください。ありがとうございました。

4

2 に答える 2

4

画像を元のサイズで表示したい場合

  • AutoSizeのプロパティToolStripを設定true
  • ImageScalingのプロパティToolStripItemを設定None

画像を特定のサイズで表示したい場合

  • AutoSizeのプロパティToolStripを設定true
  • ImageScalingSizeのプロパティを特定のサイズに設定ToolStripします。たとえば、32,32
  • ImageScalingのプロパティToolStripItemを設定SizeToFit
于 2015-11-04T12:07:50.370 に答える
1

うまくいけば、これは役に立ちます

Partial Public Class Form1
    Inherits Form
    Public Sub New()
        InitializeComponent()
        'using new render instead of def render
        toolStrip1.Renderer = New MyRenderer()
    End Sub
    Private Class MyRenderer
        'apply everything of default render
        Inherits ToolStripProfessionalRenderer

        'this will override the Render Butoon Bg event
        Protected Overrides Sub OnRenderButtonBackground(e As ToolStripItemRenderEventArgs)
            'if image is nothing then use the def render
            If e.Item.BackgroundImage Is Nothing Then
                MyBase.OnRenderButtonBackground(e)
            Else

                'redraw the image to fit the area
                Dim bounds As New Rectangle(Point.Empty, e.Item.Size)
                e.Graphics.DrawImage(e.Item.BackgroundImage, bounds)
                ' Something...
                If e.Item.Pressed Then
                    ' Something...
                ElseIf e.Item.Selected Then
                End If

                'draw the fit button here
                Using pen As New Pen(Color.Black)
                    e.Graphics.DrawRectangle(pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1)
                End Using
            End If
        End Sub
    End Class
End Class
于 2015-11-04T10:13:20.137 に答える