Click here to Skip to main content
15,844,602 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
Hi ...

I just can button in rectangular style, so i want to know how i can make a button that don't be rectangular and be s.t like circle and some thing like this...

Good Luck
Posted
Comments
Perry Bruins 14-Apr-11 10:11am    
Please elaborate which presentation framework you are using... Is it winforms, WPF, Silverlight?
WPF and Silverlight allow you to template any control to your likings, whether being rectangulr, circular triangular or whatever form you wish...
Sergey Alexandrovich Kryukov 15-Apr-11 0:37am    
Tag it!
--SA

There are lots of button controls on CodeProject:
http://www.codeproject.com/KB/buttons/[^]

For example, this one:
RoundButton Windows Control - Ever Decreasing Circles[^]
 
Share this answer
 
0) Winforms - You have to create a custom control that at least overrides the Paint event.

1) WPF or Silverlight - you have to come up with your own style/data template and draw the desired shape. (You could also just create an image and use that in your custom style.

2) ASP.Net - just come up with a button image with the desired shape, and use that as the button on your web page.

In the end, Google is your friend.
 
Share this answer
 
v2
A few days ago,I wrote one. Here,I will give you.
XML
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 System.Drawing.Drawing2D ;

namespace myTrackBar
{
    public partial class button : Button
    {
        private Color color1 =Color.White  ;
        private Color color2 = Color.FromArgb(81, 198, 255);
        public button()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.UserPaint, true);//自动重绘
        }
        /// <summary>
        /// 画圆形按钮
        /// </summary>
        /// <param name="pe"></param>
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;//使边框平滑
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse (this.ClientRectangle);//画椭圆
            PathGradientBrush pbr = new PathGradientBrush(path);
            pbr.CenterColor = color1;
            Color[] colors = { color2  };
            pbr.SurroundColors = colors;
            pe.Graphics.FillPath(pbr, path);//填充椭圆
            DrawText(pe);//椭圆上写字
            this.Region = new Region(path);

        }
        /// <summary>
        /// 在按钮上写字
        /// </summary>
        /// <param name="e"></param>
        private void DrawText(PaintEventArgs e)
        {
            float x = this.Width  / 2-4;
            float y = this.Height / 2-4;
            e.Graphics.DrawString(this.Text , this.Font, new SolidBrush(Color.Red),x,y);//指定位置写字
        }
        /// <summary>
        /// 鼠标指定后改变颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_MouseEnter(object sender, EventArgs e)
        {
            color2 = Color.Pink;
        }
        /// <summary>
        /// 鼠标离开颜色复原
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_MouseLeave(object sender, EventArgs e)
        {
            color2 = Color.FromArgb(81, 198, 255);

        }
    }
}
 
Share this answer
 
Comments
Olivier Levrey 14-Apr-11 16:51pm    
This answer doesn't deserve 2. Have a 5.
hjl243632044 15-Apr-11 10:21am    
why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900