C# .NET - C# 3.0 - Creating Round button and making it looking 3D

Asked By Aldo Liaks on 06-Jun-08 03:22 AM

Hi guys,

I am using the code below to create a round button (from: http://msdn.microsoft.com/en-us/system.windows.forms.control.region.aspx)

It works nice. The problem is that the result round button looks flat (very flat), and I need it looking like 3D... (more sofisticated...)

How can I get it done?

Thanks in advance,

Aldo.

 

private void roundButton_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

        {

            System.Drawing.Drawing2D.GraphicsPath buttonPath = new System.Drawing.Drawing2D.GraphicsPath();

 

            // Set a new rectangle to the same size as the button's ClientRectangle property.

            System.Drawing.Rectangle newRectangle = roundButton.ClientRectangle;

 

            // Decrease the size of the rectangle.

            newRectangle.Inflate(-10, -10);

 

            // Draw the button's border.

            e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);

 

            // Increase the size of the rectangle to include the border.

            newRectangle.Inflate(1, 1);

 

            // Create a circle within the new rectangle.

            buttonPath.AddEllipse(newRectangle);

 

            // Set the button's Region property to the newly created circle region.

            roundButton.Region = new System.Drawing.Region(buttonPath);

        }

 

do you want to try this third party activex control... i think its a freeware

sundar k replied to Aldo Liaks on 06-Jun-08 03:58 AM

3D Active Button Magic is the ultimate button ActiveX control developed with the purpose of replacing the old fashioned Windows flat-square button in applications written with the most diffused development environments that accept ActiveX controls such as Visual Studio 6.0, Visual Studio.NET and Delphi.

3D Active Button Magic 8.10

http://www.programmersheaven.com/download/17320/download.aspx

check this... - Santhosh N replied to Aldo Liaks on 06-Jun-08 04:56 AM

Check this if it addresses your issue in creating a 3d style button..

http://www.codeproject.com/KB/buttons/RoundButton_csharp.aspx

Or else you can create a flash (or any other approach to create button) button for this and use it c#

reply - alice johnson replied to Aldo Liaks on 06-Jun-08 01:44 PM

this is not exactly wat you want but it will surely help you get 3d style.Hope it helps

using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Create a pen and font
Graphics g = e.Graphics;
Pen blackPen =
new Pen(Color.Black, 2);
Font verdanaFont =
new Font( "Verdana", 60, FontStyle.Bold);
// Create points that define polygon.
Point[] curvePoints1 = { new Point(200, 15),
new Point(200, 200), new Point(375, 250) };
Point[] curvePoints2 = {
new Point(0, 250),
new Point(200, 200), new Point(375, 250) };
Point[] curvePoints3 = {
new Point(200, 15),
new Point(200, 200), new Point(0, 250) };
// Create linear gradient brushes
Point pt1 = new Point(10, 10);
Point pt2 =
new Point(30, 30);
LinearGradientBrush lgBrush1 =
new LinearGradientBrush(pt1, pt2, Color.Red, Color.Blue);
LinearGradientBrush lgBrush2 =
new LinearGradientBrush(pt1, pt2, Color.Red, Color.Green);
LinearGradientBrush lgBrush3 =
new LinearGradientBrush(pt1, pt2, Color.Blue, Color.Green);
// If you want to draw three lines
//e.Graphics.DrawLine(blackPen, 200, 55, 200, 200);
//e.Graphics.DrawLine(blackPen, 50, 250, 200, 200);
//e.Graphics.DrawLine(blackPen, 345, 260, 200, 200);
// Set quality of text and shape
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.SmoothingMode = SmoothingMode.AntiAlias;
// Draw three polygons and string
e.Graphics.FillPolygon(new SolidBrush(Color.FromArgb(80, 255, 0, 0)), curvePoints1);
e.Graphics.FillPolygon(
new SolidBrush(Color.FromArgb(80, 0, 255, 0)), curvePoints2);
e.Graphics.FillPolygon(
new SolidBrush(Color.FromArgb(80, 0, 0, 255)), curvePoints3);
// Draw C# using the DrawString method
// Starting @ point 140, 150
g.DrawString("C#", verdanaFont, lgBrush1, new PointF(140,150) );
// Dispose Graphics
g.Dispose();
}

See this link too

http://www.c-sharpcorner.com/UploadFile/mahesh/CSCorner3DLogo10102005013605AM/CSCorner3DLogo.aspx

http://www.codeguru.com/csharp/.net/net_general/graphics/article.php/c11375/

Creating 3D Buttons - Swapnil Salunke replied to Aldo Liaks on 06-Jun-08 02:42 PM

Hello

You can use pen and brush to hadle this.
You have to extend the ButtonClass And have to handle the paint event so should have take care of the thing if User Clicks on the Button part.

There is a helpful article on this just go through it will help you surely.

http://www.codeproject.com/KB/buttons/RoundButton_csharp.aspx

Happy Coding
Takecare


bala replied to Swapnil Salunke on 16-Sep-10 06:13 AM


i  need my .net  butten in 3d view