how to show image in disabled button?
i had placed image and backgrou开发者_开发百科ndimage in button control in vb.net if button is in disable state,image also shown as disabled(there is no color of image) state.but i want an image as enable (ie.image should be in color) and at the same time button will be disable
Create a user control that inherits from the Button Class, then override the OnPaint() method.
Note that after inheriting your user control, you will see a message indicating a fix is required in the partial-class for your control, use the IDE's suggestion to fix this, and remove the (now) obsolete AutoScaleMode property from the designer code (in the constructor).
Edit: I was wrong, you have to override the OnPaint() method, and completely draw the button, including it's text.
Public Class myButton : Inherits System.Windows.Forms.Button
Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)
'MyBase.OnPaint(pevent)
pevent.Graphics.DrawImage(myimage, 0, 0, myimage.Width, myimage.Height)
pevent.Graphics.DrawString(Me.Text, Me.Font, SystemBrushes.GrayText, 0, 0)
End Sub
End Class
精彩评论