Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. protected override void OnPaint(PaintEventArgs e)
  2. {
  3. base.OnPaint(e);
  4.  
  5. SolidBrush brush;
  6. Rectangle r = new Rectangle(this.Bounds.Width - 20, 2, 16, 17);
  7.  
  8. // If click on Del(Close Icon)
  9. if (bOnDel)
  10. {
  11. brush = new SolidBrush(Color.LightBlue);
  12. e.Graphics.FillRectangle(brush, r);
  13. brush.Color = Color.Blue;
  14. e.Graphics.DrawRectangle(new Pen(brush, 1), r);
  15. }
  16. // If didn't click on Del(Close Icone)
  17. if (!bOnDel)
  18. {
  19.  
  20. brush = new SolidBrush(Color.FromKnownColor(KnownColor.Transparent));
  21. e.Graphics.FillRectangle(brush, r);
  22. brush.Color = Color.FromKnownColor(KnownColor.Transparent);
  23. e.Graphics.DrawRectangle(new Pen(brush, 1), r);
  24. }
  25.  
  26. //Code for Drawing Cross Lines
  27.  
  28. brush = new SolidBrush(Color.Gray);
  29. Rectangle rCross = new Rectangle(this.Bounds.Width - 15, 8, 6, 6);
  30. e.Graphics.DrawLine(new Pen(brush, 2), new Point(rCross.Right, rCross.Top), new Point(rCross.Left, rCross.Bottom));
  31. e.Graphics.DrawLine(new Pen(brush, 2), new Point(rCross.Left, rCross.Top), new Point(rCross.Right, rCross.Bottom));
  32. }
  33.  
  34. private void yourToolStripMenuItem_MouseLeave(object sender, EventArgs e)
  35. {
  36. ((ToolStripMenuItem)sender).BackColor = Color.Red;
  37. }
  38.  
  39. public partial class CustomControl1 : ToolStripMenuItem
  40. {
  41. Rectangle r;
  42. bool entered;
  43.  
  44. public CustomControl1()
  45. {
  46. InitializeComponent();
  47. }
  48.  
  49. protected override void OnPaint(PaintEventArgs e)
  50. {
  51. base.OnPaint(e);
  52.  
  53. SolidBrush brush;
  54. r = new Rectangle(this.Bounds.Width - 20, 2, 16, 17);
  55.  
  56. // If MouseEnter Del(Close Icon)
  57. if (entered)
  58. {
  59. brush = new SolidBrush(Color.LightBlue);
  60. e.Graphics.FillRectangle(brush, r);
  61. brush.Color = Color.Blue;
  62. e.Graphics.DrawRectangle(new Pen(brush, 1), r);
  63. }
  64. // If Mouse Not Entered Del(Close Icone)
  65. if (!entered)
  66. {
  67.  
  68. brush = new SolidBrush(Color.FromKnownColor(KnownColor.Transparent));
  69. e.Graphics.FillRectangle(brush, r);
  70. brush.Color = Color.FromKnownColor(KnownColor.Transparent);
  71. e.Graphics.DrawRectangle(new Pen(brush, 1), r);
  72. }
  73.  
  74. //Code for Drawing Cross Lines
  75.  
  76. brush = new SolidBrush(Color.Gray);
  77. Rectangle rCross = new Rectangle(this.Bounds.Width - 15, 8, 6, 6);
  78. e.Graphics.DrawLine(new Pen(brush, 2), new Point(rCross.Right, rCross.Top), new Point(rCross.Left, rCross.Bottom));
  79. e.Graphics.DrawLine(new Pen(brush, 2), new Point(rCross.Left, rCross.Top), new Point(rCross.Right, rCross.Bottom));
  80. }
  81.  
  82. protected override void OnMouseMove(MouseEventArgs e)
  83. {
  84. base.OnMouseMove(e);
  85.  
  86. if (r.Contains(e.X, e.Y) && !entered)
  87. {
  88. entered = true;
  89. Invalidate(r);
  90. }
  91. else if (!r.Contains(e.X, e.Y) && entered)
  92. {
  93. entered = false;
  94. Invalidate(r);
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement