Just to give you a hint into the right direction :
This would make a circle shaped button :
This would make a square button :Code:private void butCCircle_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { //Declare A GraphicsPath Object, Which Is Used To Draw The Shape Of The Button System.Drawing.Drawing2D.GraphicsPath CirclePath = new System.Drawing.Drawing2D.GraphicsPath(); //Create A 60 x 60 Circle Path CirclePath.AddEllipse(new Rectangle(0, 0, 60, 60)); //Size Of The Button butCCircle.Size = new System.Drawing.Size(60, 60); if (blnCircleClicked) { //If The Button Is Selected To Draw, Change The Color butCCircle.BackColor = Color.DeepSkyBlue; } else { //If The Button Is Not Selected To Draw With, Change Back To Original Color butCCircle.BackColor = Color.Aquamarine; } //Create The Circular Shaped Button, Based On The Graphics Path butCCircle.Region = new Region(CirclePath); //Release All Resources Owned By The Graphics Path Object CirclePath.Dispose(); }
This would make a triangular button :Code:private void butCSquare_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { //Declare A GraphicsPath Object, Which Is Used To Draw The Shape Of The Button System.Drawing.Drawing2D.GraphicsPath SquarePath = new System.Drawing.Drawing2D.GraphicsPath(); //Create A 60 x 60 Square Path SquarePath.AddRectangle(new Rectangle(0, 0, 60, 60)); //Size Of The Button butCSquare.Size = new System.Drawing.Size(60, 60); if (blnSquareClicked) { //If The Button Is Selected To Draw, Change The Color butCSquare.BackColor = Color.DeepSkyBlue; } else { //If The Button Is Not Selected To Draw With, Change Back To Original Color butCSquare.BackColor = Color.Aquamarine; } //Create The Square Shaped Button, Based On The Graphics Path butCSquare.Region = new Region(SquarePath); //Release All Resources Owned By The Graphics Path Object SquarePath.Dispose(); }
On the other hand, instead of making a button shaped from a bitmap, why not use the picture as the button instead ¿Code:private void butCTriangle_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { //Declare A GraphicsPath Object, Which Is Used To Draw The Shape Of The Button System.Drawing.Drawing2D.GraphicsPath TrianglePath = new System.Drawing.Drawing2D.GraphicsPath(); //Create A Triangle Path, With A Total Width And Height Of 60, The Lines From The Bottom Meet At 30 At The Top Point[] pTPoints = {new Point(30, 0), new Point(60, 60), new Point(0, 60)}; //Add The Point Array Object To The GraphicsPath Object. The Point Array Is Needed To Create The Three Interconnected Points TrianglePath.AddLines(pTPoints); //Size Of The Button butCTriangle.Size = new System.Drawing.Size(60, 60); if (blnTriangleClicked) { //If The Button Is Selected To Draw, Change The Color butCTriangle.BackColor = Color.DeepSkyBlue; } else { //If The Button Is Not Selected To Draw With, Change Back To Original Color butCTriangle.BackColor = Color.Aquamarine; } //Create The Triangular Shaped Button, Based On The Graphics Path butCTriangle.Region = new Region(TrianglePath); //Release All Resources Owned By The Graphics Path Object TrianglePath.Dispose(); }
I hope my comments were useful




Reply With Quote