blacksource
August 20th, 2008, 10:00 PM
how to create irregular shape button from bitmap?
|
Click to See Complete Forum and Search --> : how to create irregular shape button? blacksource August 20th, 2008, 10:00 PM how to create irregular shape button from bitmap? HanneSThEGreaT August 21st, 2008, 12:58 AM Just to give you a hint into the right direction : This would make a circle shaped button : 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 square button : 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(); } This would make a triangular button : 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(); } On the other hand, instead of making a button shaped from a bitmap, why not use the picture as the button instead ¿ I hope my comments were useful blacksource August 22nd, 2008, 12:37 AM Thank you Falcon Eyes May 31st, 2009, 05:24 AM thanks but should i create custom control then the above code to it dglienna May 31st, 2009, 10:17 AM You should draw all the controls at the same time, in some INIT code, that you can also call to CLEAR the form This way would draw the button every time you invalidated the form HanneSThEGreaT June 1st, 2009, 01:19 AM thanks but should i create custom control then the above code to it No. As you can see in my previous post ( Post #2 (http://www.codeguru.com/forum/showpost.php?p=1753865&postcount=2) ), all you need is the particular button's Paint event, and do all the drawing code in there. :) codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |