如何制作一个不是矩形的并且像圆圈一样的按钮 [英] How to make a button that don't be RECTANGULAR and be s.t like circle

查看:88
本文介绍了如何制作一个不是矩形的并且像圆圈一样的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

我只是可以按矩形按钮,所以我想知道如何制作一个不是矩形的按钮,而不是像圆形和类似这样的东西...

祝您好运

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

推荐答案

CodeProject上有很多按钮控件:
http://www.codeproject.com/KB/buttons/ [ RoundButton Windows控件-不断减少的圆圈 [
There are lots of button controls on CodeProject:
http://www.codeproject.com/KB/buttons/[^]

For example, this one:
RoundButton Windows Control - Ever Decreasing Circles[^]


0)Winforms-您必须创建一个自定义控件至少覆盖Paint事件.

1)WPF或Silverlight-您必须拿出自己的样式/数据模板并绘制所需的形状. (您也可以只创建图像并以自定义样式使用它.

2)ASP.Net-只需拿出具有所需形状的按钮图像,然后将其用作网页上的按钮即可.

最后,Google是您的朋友.
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.


几天前,我写了一个.在这里,我给你.
A few days ago,I wrote one. Here,I will give you.
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);

        }
    }
}


这篇关于如何制作一个不是矩形的并且像圆圈一样的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆