just like we bring JButton images in java..............can we bring that type of 3Dbutton images on buttons in c# forms

Edited 5 Years Ago by Jessurider: n/a

Draw them? :) Wouldn't be much fun, but I'm sure you could? If not, maybe there's a library out there you can buy, or you could use images?

Just some quick thoughts.

in the attachment u see a button..............i did that in java in Netbeans IDE..............but i cant do that similarly in visual studio 2008 (C#) forms

.NET now has two types of forms programming: The traditional Winforms and WPF.

Winforms are designed to have a similar look and feel so that users will be able to easily figure out what to do as they see common controls that look the same no matter what program they are running. It is possible to override the look/feel be designing your own controls and handling the drawing yourself but that defeats the purpose of Winforms.

But, people wanted fancier forms, so WPF was created. WPF supports custom look and feel controls, animation, etc.

So when you start your project, you need to determine which type of application you are creating: One with a standard look/feel, or a custom look/feel. It appears you want a custom look/feel so you'll be best off if you use WPF.

If you are not yet into WPF, like me.
You could use the Image and ImageList properties of a Button, to simulate a 3D effect.
See this video.
Or you could derive from the button class, and play around with some color gradients, like I did here:

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace CalculatorApp
{
    // Class for "3D" oval or circle button
    // just using a color trick to simulate a 3D effect
    //
    class RoundButton : Button
    {
        private Color _startcolor = Color.White;
        private Color _endcolor = Color.Black;
        private Color _textcolor = Color.Black;
        private bool _swap = false;

        //default constructor
        public RoundButton(){}

        public RoundButton(Color startcolor, Color endcolor) 
        {
            _startcolor = startcolor;
            _endcolor = endcolor;
        }

        public Color Startcolor 
        { 
            get { return _startcolor;}            
            set { _startcolor = value;} 
        }

        public Color Endcolor
        {
            get { return _endcolor; }
            set { _endcolor = value; }
        }

        public Color Textcolor
        {
            get { return _textcolor; }
            set { _textcolor = value; }
        }

        private void DoDraw(Graphics G, bool sw) //sw does the color swap, quicker than a swap routine!
        {
            Brush textBr = new SolidBrush(_textcolor);
            Rectangle R = new Rectangle(0, 0, this.Width, this.Height);
            StringFormat strFormat = new StringFormat();
            strFormat.Alignment = StringAlignment.Center;
            strFormat.LineAlignment = StringAlignment.Center;

            G.SmoothingMode = SmoothingMode.HighQuality;    // change??????
            //G.InterpolationMode = InterpolationMode.NearestNeighbor;
            G.PixelOffsetMode = PixelOffsetMode.HighQuality;// change?????? 
            //Rectangle R2 = R;
            //R2.Inflate(-2, -2);
            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(R);
            this.Region = new Region(path);

            R.Inflate(1, 1);
            //R.Inflate(R.Size);
            LinearGradientBrush linBr;
            if (sw)
                linBr = new LinearGradientBrush
                    (new Point(R.Left, R.Top), new Point(R.Right, R.Bottom), _endcolor, _startcolor);
            else
                linBr = new LinearGradientBrush
                   (new Point(R.Left, R.Top), new Point(R.Right, R.Bottom), _startcolor, _endcolor);
            //////////////
            //R.Inflate(-1, -1); 
            //Pen pen = new Pen(_startcolor); 
            //pen.Width = 1f; 
            //G.DrawEllipse(pen, R);
            //R.Inflate(1, 1);
            G.FillEllipse(linBr, R);

            R.Inflate(-5, -5);
            LinearGradientBrush linBrBack;
            if (sw)
                linBrBack = new LinearGradientBrush
                    (new Point(R.Left, R.Top), new Point(R.Right, R.Bottom), _startcolor, _endcolor);
            else
                 linBrBack = new LinearGradientBrush
                    (new Point(R.Left, R.Top), new Point(R.Right, R.Bottom), _endcolor, _startcolor);
            G.FillEllipse(linBrBack, R);

            G.DrawString(this.Text, this.Font, textBr, R, strFormat);
        }

        protected override void OnPaint(PaintEventArgs pevent)
        {
            //base.OnPaint(pevent);
            DoDraw(pevent.Graphics, _swap);    
        }

        protected override void OnMouseHover(EventArgs e) // not needed really, but nice to have
        {
            Graphics g = this.CreateGraphics();
            _swap = true;
            DoDraw(g, _swap);
            _swap = false;
            g.Dispose();
            base.OnMouseHover(e);
        }
    }
}

I give this as is.
As you can see from the code I'm still working on this one. Think I'll switch to WPF instead!;)

Edited 5 Years Ago by ddanbe: n/a

ddanbe,

I'm with you. WPF is odd to me. The whole thing is unfamiliar and every time I try working with it I get frustrated and end up deleting whatever I spent hours on with nothing to show for it (don't tell anyone...I still get paid for it) but I think I'm going to have to bite the bullet and figure it out eventually. I just wonder if it's a fad.

I've always been under the impression that a fancy, dramatic, colourful UI is just a cover for poor programming. Course that's not true, but it's been my perception for a long time. I'd rather spend more time making the application work, and work well and be intuitive than work on flair.

Just my opinion though.

Comments
Well said!

@zachattack05
Quite right!
It is indeed often so that poor appl development is hidden behind "fancy" UI.
But "fancy" UI makes life of users more pleasing... if the app is OK that is...

This article has been dead for over six months. Start a new discussion instead.