Cross in Button

georgepatotk

Contributor
Joined
Mar 1, 2004
Messages
432
Location
Malaysia
I would like to draw a Cross sign on the top of button. The button.BackgroundImage is already set to a picture, and I would like to draw the big X on the top of the button instead of button.Enabled=False.

any comments?

Thanks in advance.
 

Attachments

Easiest way would probably be to call .CreateGraphics on the button and then draw onto this - something like

Visual Basic:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

Dim g As Graphics = Button1.CreateGraphics
g.DrawLine(Pens.Red, 0, 0, Button1.ClientRectangle.Width, Button1.ClientRectangle.Height)
g.DrawLine(Pens.Red, Button1.ClientRectangle.Width, 0, 0, Button1.ClientRectangle.Height)
g.Dispose()

End Sub
should do the trick.
 
Thanks, it works... I really appreciate... :P

But, I am now thinking, in which event should be overrides.. cause once mouse_over fire, the cross gone..
 
Handle button Paint event

Ideally you'd use the button's Paint event:

Visual Basic:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'Attach to Paint event
    AddHandler myButton.Paint, AddressOf DrawButton

End Sub

'Handle the event
Private Sub DrawButton(ByVal sender As Object, ByVal e As PaintEventArgs)

    'Draw cross
    e.Graphics.DrawLine(Pens.Red, 0, 0, myButton.ClientRectangle.Width, myButton.ClientRectangle.Height)
    e.Graphics.DrawLine(Pens.Red, myButton.ClientRectangle.Width, 0, 0, myButton.ClientRectangle.Height)
    'Dispose not required

End Sub

Good luck :cool:
 
Back
Top