Chocolade19721309

Untitled

May 7th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. using GlowButton;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using static GlowButton.GlowButton;
  11.  
  12. namespace GlowButton_Harness
  13. {
  14. public partial class frmMain : Form
  15. {
  16. public enum ButtonBehavior
  17. {
  18. Default,
  19. StayClicked,
  20. Toggle,
  21. DisableOnPress,
  22. Popup
  23. // Add more behaviors as needed
  24. }
  25.  
  26. private GlowButton.GlowButton glowButton1;
  27.  
  28. public frmMain()
  29. {
  30. InitializeComponent();
  31.  
  32. Image originalImage = Image.FromFile(@"D:\Csharp Projects\Screen Recorder\Resources\pngimg.com - buttons_PNG152.png");
  33. Image resizedImage = ResizeImage(originalImage, new Size(100, 100));
  34.  
  35. glowButton1 = new GlowButton.GlowButton
  36. {
  37. Image = resizedImage,
  38. Size = new Size(100, 100),
  39. Location = new Point(10, (this.ClientSize.Height - 100) / 2),
  40. ApplyDarkEffect = true // Assuming you have this property to toggle the dark effect
  41. };
  42.  
  43. this.Controls.Add(glowButton1);
  44.  
  45. SetButtonBehavior(glowButton1, ButtonBehavior.Default);
  46.  
  47. SetButtonBehavior(glowButton4, ButtonBehavior.Toggle);
  48. SetButtonBehavior(glowButton5, ButtonBehavior.DisableOnPress);
  49. }
  50.  
  51. private Image ResizeImage(Image imgToResize, Size size)
  52. {
  53. Bitmap b = new Bitmap(size.Width, size.Height);
  54. using (Graphics g = Graphics.FromImage((Image)b))
  55. {
  56. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  57. g.DrawImage(imgToResize, 0, 0, size.Width, size.Height);
  58. }
  59. return (Image)b;
  60. }
  61.  
  62. private void SetButtonBehavior(GlowButton.GlowButton button, ButtonBehavior behavior)
  63. {
  64. button.Click -= DefaultButtonClick; // Remove existing handlers to avoid multiple subscriptions
  65.  
  66. switch (behavior)
  67. {
  68. case ButtonBehavior.Default:
  69. // Normal button behavior
  70. button.Click += DefaultButtonClick;
  71. break;
  72. case ButtonBehavior.StayClicked:
  73. // Stays clicked until clicked again
  74. button.Click += (s, e) => { button.Enabled = !button.Enabled; };
  75. break;
  76. case ButtonBehavior.Toggle:
  77. // Toggles some state on and off
  78. bool isToggled = false;
  79. button.Click += (s, e) => { isToggled = !isToggled; /* Toggle functionality */ };
  80. break;
  81. case ButtonBehavior.DisableOnPress:
  82. // Disables the button once clicked
  83. button.Click += (s, e) => { button.Enabled = false; };
  84. break;
  85. case ButtonBehavior.Popup:
  86. // Opens a new form or dialog
  87. button.Click += (s, e) => { new Form().ShowDialog(); };
  88. break;
  89. }
  90.  
  91. // Redraw or update the button if necessary
  92. button.Invalidate();
  93. }
  94.  
  95. private void DefaultButtonClick(object sender, EventArgs e)
  96. {
  97. System.Diagnostics.Debug.Print("Default button clicked");
  98. }
  99.  
  100. private void glowButton2_MouseClick(object sender, MouseEventArgs e)
  101. {
  102. System.Diagnostics.Debug.Print("glowButton2 clicked");
  103. }
  104.  
  105. private void glowButton3_MouseClick(object sender, MouseEventArgs e)
  106. {
  107. System.Diagnostics.Debug.Print("glowButton3 clicked");
  108. }
  109.  
  110. private void glowButton4_MouseClick(object sender, MouseEventArgs e)
  111. {
  112. System.Diagnostics.Debug.Print("glowButton4 clicked");
  113. }
  114.  
  115. private void glowButton5_MouseClick(object sender, MouseEventArgs e)
  116. {
  117. System.Diagnostics.Debug.Print("glowButton5 clicked");
  118. }
  119.  
  120. private void glowButton6_MouseClick(object sender, MouseEventArgs e)
  121. {
  122. System.Diagnostics.Debug.Print("glowButton6 clicked");
  123. }
  124.  
  125. private void glowButton7_MouseClick(object sender, MouseEventArgs e)
  126. {
  127. System.Diagnostics.Debug.Print("glowButton7 clicked");
  128. }
  129.  
  130. private void glowButton8_MouseClick(object sender, MouseEventArgs e)
  131. {
  132. System.Diagnostics.Debug.Print("glowButton8 clicked");
  133. }
  134.  
  135. private void glowButton9_MouseClick(object sender, MouseEventArgs e)
  136. {
  137. System.Diagnostics.Debug.Print("glowButton9 clicked");
  138. }
  139.  
  140. private void frmMain_Paint(object sender, PaintEventArgs e)
  141. {
  142. if (glowButton1 != null)
  143. {
  144. DrawButtonText(e.Graphics, "REC", glowButton1);
  145. }
  146. }
  147.  
  148. private void DrawButtonText(Graphics graphics, string _buttonText, GlowButton.GlowButton gb)
  149. {
  150. using (Font font = new Font("Arial", 12, FontStyle.Bold))
  151. {
  152. SizeF textSize = graphics.MeasureString(_buttonText, font);
  153. PointF locationToDraw = new PointF((gb.ClientSize.Width / 2) - (textSize.Width / 2), (gb.ClientSize.Height / 2) - (textSize.Height / 2));
  154.  
  155. using (SolidBrush brush = new SolidBrush(Color.White)) // Ensure text color contrasts well with button
  156. {
  157. graphics.DrawString(_buttonText, font, brush, locationToDraw);
  158. }
  159. }
  160. }
  161. }
  162. }
  163.  
Advertisement
Add Comment
Please, Sign In to add comment