.net圆形按钮的实现

一.设计时效果

.net圆形按钮的实现_第1张图片

.net圆形按钮的实现_第2张图片

二.运行时效果

三.简单的实现思路

  因为在最近的项目中要用到类似效果的控件,所以就索性做了一个.原理很简单,实现的代码不超过250行.继承control类,然后在onpaint方法中来绘制按钮效果,指定Region,同时,要在Onmousedown,Onmouseenter,Onmouseup,Onmouseleave,OnResize,OnLostFocus等方法中做一些相应的处理.

四.部分源代码 

 



 protected override void OnLostFocus(EventArgs e)
        
{
            
base.OnLostFocus(e);
            
this._isEnter = false;
            
this.Invalidate();
        }

        
protected override void OnMouseDown(MouseEventArgs e)
        
{
            
base.OnMouseDown(e);
            
this.Capture = true;
            _isEnter 
= true;
            
this._mouseStyle = MouseStyle.MouseDown;
            
this.Invalidate();
            
if (e.Button == MouseButtons.Left)
            
{
                
if (this.ButtonClick != null)
                    
this.ButtonClick();
            }

        }

        
protected override void OnMouseHover(EventArgs e)

          y=''none''; document.getElementById(''_657_787_Open_Text'').style.display=''none''; document.getElementById(''_657_787_Closed_Image'').style.display=''inline''; document.getElementById(''_657_787_Closed_Text'').style.display=''inline'';" align="top" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" />        {
            
base.OnMouseHover(e);
            
this._mouseStyle = MouseStyle.MouseHover;
            
this.Invalidate(); 
        }

        
protected override void OnMouseUp(MouseEventArgs e)
        
{
            
base.OnMouseUp(e);
            
this._mouseStyle = MouseStyle.MouseHover;
            
this.Invalidate(); 
        }

        
protected override void OnMouseEnter(EventArgs e)
        
{
            
base.OnMouseEnter(e);
            
this._mouseStyle = MouseStyle.MouseHover;
            
this.Invalidate(); 
        }

        protected override void OnMouseLeave(EventArgs e)
        
{
            
base.OnMouseLeave(e);
            
this._mouseStyle = MouseStyle.None;
            
this.Invalidate(); 
        }

        
protected override void OnResize(EventArgs e)
        
{
            
base.OnResize(e);
            
this.Height = this.Width;
        }

 

你可能感兴趣的:(.net圆形按钮的实现)