Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using GlowButton;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using static GlowButton.GlowButton;
- namespace GlowButton_Harness
- {
- public partial class frmMain : Form
- {
- public enum ButtonBehavior
- {
- Default,
- StayClicked,
- Toggle,
- DisableOnPress,
- Popup
- // Add more behaviors as needed
- }
- private GlowButton.GlowButton glowButton1;
- public frmMain()
- {
- InitializeComponent();
- Image originalImage = Image.FromFile(@"D:\Csharp Projects\Screen Recorder\Resources\pngimg.com - buttons_PNG152.png");
- Image resizedImage = ResizeImage(originalImage, new Size(100, 100));
- glowButton1 = new GlowButton.GlowButton
- {
- Image = resizedImage,
- Size = new Size(100, 100),
- Location = new Point(10, (this.ClientSize.Height - 100) / 2),
- ApplyDarkEffect = true // Assuming you have this property to toggle the dark effect
- };
- this.Controls.Add(glowButton1);
- SetButtonBehavior(glowButton1, ButtonBehavior.Default);
- SetButtonBehavior(glowButton4, ButtonBehavior.Toggle);
- SetButtonBehavior(glowButton5, ButtonBehavior.DisableOnPress);
- }
- private Image ResizeImage(Image imgToResize, Size size)
- {
- Bitmap b = new Bitmap(size.Width, size.Height);
- using (Graphics g = Graphics.FromImage((Image)b))
- {
- g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
- g.DrawImage(imgToResize, 0, 0, size.Width, size.Height);
- }
- return (Image)b;
- }
- private void SetButtonBehavior(GlowButton.GlowButton button, ButtonBehavior behavior)
- {
- button.Click -= DefaultButtonClick; // Remove existing handlers to avoid multiple subscriptions
- switch (behavior)
- {
- case ButtonBehavior.Default:
- // Normal button behavior
- button.Click += DefaultButtonClick;
- break;
- case ButtonBehavior.StayClicked:
- // Stays clicked until clicked again
- button.Click += (s, e) => { button.Enabled = !button.Enabled; };
- break;
- case ButtonBehavior.Toggle:
- // Toggles some state on and off
- bool isToggled = false;
- button.Click += (s, e) => { isToggled = !isToggled; /* Toggle functionality */ };
- break;
- case ButtonBehavior.DisableOnPress:
- // Disables the button once clicked
- button.Click += (s, e) => { button.Enabled = false; };
- break;
- case ButtonBehavior.Popup:
- // Opens a new form or dialog
- button.Click += (s, e) => { new Form().ShowDialog(); };
- break;
- }
- // Redraw or update the button if necessary
- button.Invalidate();
- }
- private void DefaultButtonClick(object sender, EventArgs e)
- {
- System.Diagnostics.Debug.Print("Default button clicked");
- }
- private void glowButton2_MouseClick(object sender, MouseEventArgs e)
- {
- System.Diagnostics.Debug.Print("glowButton2 clicked");
- }
- private void glowButton3_MouseClick(object sender, MouseEventArgs e)
- {
- System.Diagnostics.Debug.Print("glowButton3 clicked");
- }
- private void glowButton4_MouseClick(object sender, MouseEventArgs e)
- {
- System.Diagnostics.Debug.Print("glowButton4 clicked");
- }
- private void glowButton5_MouseClick(object sender, MouseEventArgs e)
- {
- System.Diagnostics.Debug.Print("glowButton5 clicked");
- }
- private void glowButton6_MouseClick(object sender, MouseEventArgs e)
- {
- System.Diagnostics.Debug.Print("glowButton6 clicked");
- }
- private void glowButton7_MouseClick(object sender, MouseEventArgs e)
- {
- System.Diagnostics.Debug.Print("glowButton7 clicked");
- }
- private void glowButton8_MouseClick(object sender, MouseEventArgs e)
- {
- System.Diagnostics.Debug.Print("glowButton8 clicked");
- }
- private void glowButton9_MouseClick(object sender, MouseEventArgs e)
- {
- System.Diagnostics.Debug.Print("glowButton9 clicked");
- }
- private void frmMain_Paint(object sender, PaintEventArgs e)
- {
- if (glowButton1 != null)
- {
- DrawButtonText(e.Graphics, "REC", glowButton1);
- }
- }
- private void DrawButtonText(Graphics graphics, string _buttonText, GlowButton.GlowButton gb)
- {
- using (Font font = new Font("Arial", 12, FontStyle.Bold))
- {
- SizeF textSize = graphics.MeasureString(_buttonText, font);
- PointF locationToDraw = new PointF((gb.ClientSize.Width / 2) - (textSize.Width / 2), (gb.ClientSize.Height / 2) - (textSize.Height / 2));
- using (SolidBrush brush = new SolidBrush(Color.White)) // Ensure text color contrasts well with button
- {
- graphics.DrawString(_buttonText, font, brush, locationToDraw);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment