Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BasicButton : Control
- {
- private MouseState _mouseState = MouseState.Normal;
- protected override void CreateHandle()
- {
- base.CreateHandle();
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- var g = e.Graphics;
- g.Clear(Color.White);
- g.DrawString(Text, Font, new SolidBrush(ForeColor), new Point(0, 0));
- switch (_mouseState)
- {
- case MouseState.Normal: g.FillRectangle(Brushes.Orange, ClientRectangle);
- break;
- case MouseState.Down:
- g.FillRectangle(Brushes.DarkOrange, ClientRectangle);
- break;
- }
- base.OnPaint(e);
- StringFormat sf = new StringFormat();
- sf.LineAlignment = StringAlignment.Center;
- sf.Alignment = StringAlignment.Center;
- g.DrawString(Text, Font, new SolidBrush(ForeColor), new Rectangle(0, 0, Width, Height), sf);//Butchered it
- }
- private void SwitchMouseState(MouseState state)
- {
- _mouseState = state;
- Invalidate();
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- SwitchMouseState(MouseState.Normal);
- base.OnMouseUp(e);
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- SwitchMouseState(MouseState.Down);
- base.OnMouseDown(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement