georgepatotk Posted September 15, 2007 Posted September 15, 2007 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.button cross.bmp Quote George C.K. Low
Administrators PlausiblyDamp Posted September 15, 2007 Administrators Posted September 15, 2007 Easiest way would probably be to call .CreateGraphics on the button and then draw onto this - something like 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
georgepatotk Posted September 15, 2007 Author Posted September 15, 2007 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.. Quote George C.K. Low
MrPaul Posted September 16, 2007 Posted September 16, 2007 Handle button Paint event Ideally you'd use the button's Paint event: 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: Quote Never trouble another for what you can do for yourself.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.