Sign in to follow this  
N0P

C#||Gradient Animated Button||So Easy||Good Looking||

Recommended Posts

Well today i was going through my PC  and i found my custom animated button which looks outstanding this is the c# code but if you want to use it in vb you will have to create a dll and add to the toolbox.

 

 

 

Code:

[hide]   

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace AnimatedGradientButton
{
   [DefaultEvent("Click")]
   public partial class CustomButton : UserControl
   {
       int wh = 20; float ang = 45;
       Color cl0 = Color.Blue, cl1 = Color.Orange;
       Timer t = new Timer();
       string txt = "CustomButton";
       public CustomButton()
       {
           DoubleBuffered = true;
           t.Interval = 60;
           t.Start();
           t.Tick += (s, e) => { Angle  = Angle % 360 + 1; };
           ForeColor = Color.White;                  
       }
       public float Angle {
           get { return ang; }
           set { ang = value; Invalidate(); }
       }


       

       public int BorderRadius
       {
           get { return wh; }
           set { wh = value; Invalidate(); }
       }

       public Color Color0
       {
           get { return cl0; }
           set { cl0 = value; }
       }

       public Color Color1
       {
           get { return cl1; }
           set { cl1 = value; }
       }
       protected override void OnPaint(PaintEventArgs e)
       {
           e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
           GraphicsPath gp = new GraphicsPath();

           gp.AddArc(new Rectangle(0, 0, wh, wh), 180, 90);
           gp.AddArc(new Rectangle(Width - wh, 0, wh, wh), -90, 90);
           gp.AddArc(new Rectangle(Width - wh, Height - wh, wh, wh), 0, 90);
           gp.AddArc(new Rectangle(0, Height, wh, wh), 90, 90);

           e.Graphics.FillPath(new LinearGradientBrush(ClientRectangle,cl0,cl1,ang), gp);
           e.Graphics.DrawString(txt, Font, new SolidBrush(ForeColor), ClientRectangle, new StringFormat() { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center });
           base.OnPaint(e);
       }

   }
}

[/hide]

 

Here is a example used in my latest thread of the buttons!

Capture.png

:monkas: :feelsgood: :smart: :ezy:

Share this post


Link to post
Share on other sites

Thanks for sharing, i believe with this i can make better design for my projects <3

Share this post


Link to post
Share on other sites

thanks for sharing, first like!

Share this post


Link to post
Share on other sites

Thank u for make this, best

Share this post


Link to post
Share on other sites

Well today i was going through my PC  and i found my custom animated button which looks outstanding this is the c# code but if you want to use it in vb you will have to create a dll and add to the toolbox.

 

 

 

Code:

 

 

Here is a example used in my latest thread of the buttons!

Capture.png

:monkas: :feelsgood: :smart: :ezy:

 

aprriciate it vm

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this