Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / Office

Office 2007 Button

3.16/5 (22 votes)
10 Apr 2007GPL3 1   1.7K  
Button
Screenshot - ofs2007.png

Introduction

The Office2007 style button is very easy to use. Only DragDrop ToolBox.

Using the Code

C#
internal void DrawControl(Graphics e)
{
    recBounds = this.ClientRectangle;
    Rectangle m_BrushSize=new Rectangle(0, 0, 
    this.Width , this.Height / 2);

    for(int i=0;i<=40;i++)
    {
        LinearGradientBrush myLinearGradientBrush1 = 
		new System.Drawing.Drawing2D.LinearGradientBrush
		(m_BrushSize, Color.FromArgb(i,220,252,255), 
		Color.FromArgb(i,125,195,236),
        90);//top item 

        LinearGradientBrush myLinearGradientBrush=
	    new LinearGradientBrush(m_BrushSize, Color.FromArgb(i,93,174,221), 
	    Color.FromArgb(i,177,252,255),
        -90);//down item

        myLinearGradientBrush.WrapMode =System.Drawing.Drawing2D.WrapMode.TileFlipXY;
        myLinearGradientBrush1.WrapMode=System.Drawing.Drawing2D.WrapMode.TileFlipXY;

        e.FillRectangle(myLinearGradientBrush,1, this.Height/2, 
        this.Width-2 , this.Height / 2-1);//down

        e.FillRectangle(myLinearGradientBrush1,1, 1, 
        this.Width-2 , this.Height / 2);//top

        //Draw Border
        Brush brsBorder=new SolidBrush(Color.FromArgb(121,157,182));
        Pen pnsBorder=new Pen(brsBorder);

        Brush brsDot=new SolidBrush(Color.FromArgb(179,201,214));
        Pen pnsDot=new Pen(brsDot);

        e.DrawRectangle(Pens.White,this.ClientRectangle.X+1,
    	this.ClientRectangle.Y+1,this.ClientRectangle.Width-3,
    	this.ClientRectangle.Height-3);

        e.DrawLine(pnsDot,this.ClientRectangle.X,this.ClientRectangle.Y+1,
		this.ClientRectangle.X+1,this.ClientRectangle.Y+1);
        e.DrawLine(pnsDot,this.ClientRectangle.X,this.ClientRectangle.Bottom-2,
		this.ClientRectangle.X+1,this.ClientRectangle.Bottom-2);
        e.DrawLine(pnsDot,this.ClientRectangle.Right-1,this.ClientRectangle.Bottom-2,
		this.ClientRectangle.Right-2,this.ClientRectangle.Bottom-2);
        e.DrawLine(pnsDot,this.ClientRectangle.Right-1,this.ClientRectangle.Y+1,
		this.ClientRectangle.Right-2,this.ClientRectangle.Y+1);

        e.DrawLine(pnsBorder,this.ClientRectangle.X+1,this.ClientRectangle.Y,
		this.ClientRectangle.Right-2,this.ClientRectangle.Y);
        e.DrawLine(pnsBorder,this.ClientRectangle.X,this.ClientRectangle.Y+1,
		this.ClientRectangle.X,this.ClientRectangle.Bottom-2);
        e.DrawLine(pnsBorder,this.ClientRectangle.X+1,this.ClientRectangle.Bottom-1,
		this.ClientRectangle.Right-2,this.ClientRectangle.Bottom-1);
        e.DrawLine(pnsBorder,this.ClientRectangle.Right-1,this.ClientRectangle.Y+1,
		this.ClientRectangle.Right-1,this.ClientRectangle.Bottom-2);

        //////////////////////////////////////////////////////////////////end Border

        OnDrawTextAndImage(e);
        myLinearGradientBrush.Dispose();
        myLinearGradientBrush1.Dispose();
        brsBorder.Dispose();
        brsDot.Dispose();
        pnsBorder.Dispose();
        pnsDot.Dispose();
    }
}

History

  • 10th April, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)