c# - How do I make custom buttons in Visual Studio? -


i'm trying make launcher game fixes of bugs. right i'm working on interface , want make custom buttons, not generic squares, can't figure out how.

here's example images.

regular button, not moused over.

moused on / highlighted button.

i threw buttons quickly, that's want. want button highlight when mouse on it, without being inside of default square buttons.

this can done custom drawn button. this demo msdn shows how override onpaint , swap bitmaps responding onmousedown , onmouseup. image change on hover instead, swap bitmaps during onenter , onleave.

here's cut-down example linked page:

public class picturebutton : control {     image staticimage, hoverimage;     bool pressed = false;      // staticimage primary default button image      public image staticimage     {         {             return this.staticimage;         }         set {             this.staticimage = value;         }     }      // hoverimage appears when mouse enters     public image hoverimage     {         {             return this.hoverimage;         }         set {             this.hoverimage = value;         }     }      protected override void onenter(eventargs e)     {         this.pressed = true;         this.invalidate();         base.onenter(e);     }      protected override void onleave(eventargs e)     {         this.pressed = false;         this.invalidate();         base.onleave(e);     }      protected override void onpaint(painteventargs e)     {         if (this.pressed && this.hoverimage != null)             e.graphics.drawimage(this.hoverimage, 0, 0);         else             e.graphics.drawimage(this.staticimage, 0, 0);          base.onpaint(e);     } } 

Comments