C# Winforms How to draw a rectangle on a button on a mouse over?

You can just derive your own WinForms control from a Button and override the OnPaint event. In the event handler you'll have an PaintEventArg parameter that contains the property called Graphics You can use this property to draw anything you want directly where you control is located.

You can just derive your own WinForms control from a Button and override the OnPaint event. In the event handler you'll have an PaintEventArg parameter that contains the property called Graphics. You can use this property to draw anything you want directly where you control is located.

Here is an example directly from MSDN: msdn.microsoft.com/en-us/library/system.... Added: just re-read your question and found that I didn't not reply it correctly. Basically, you have to override two events and add one property showing whether your control should be painted with an overlayed rectangle or not, let's say IsDrawRectangle. As soon as the OnMouseEnter event is triggered you check if IsDrawRectangle is set and if not you set it to true and invoke this.Invalidate().

The Invalidate() method will force the control to be re-drawn and then in your OnPaint event you just again check the value of your IsDrawRectangle property and draw the rectangle if needed. You also have to override OnMouseLeave to set the property back to false and force the repaint to remove the rectangle. Added: if you need to re-draw more than just a single control (in case if your rectangle covers some other controls that need to be re-drawn) then put everything you want to be re-drawn in one container and call the Parent.Invalidate() method in your event handlers.

– Martijn Sep 8 at 8:07 I just edited my initial response to add this information. – Alexander Galkin Sep 8 at 8:09 Thanks, I've got it working! – Martijn Sep 8 at 10:13.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions