Click here to Skip to main content
15,885,646 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to Draw Circles on GUI? Pin
Stuck At Zero25-Mar-13 10:30
Stuck At Zero25-Mar-13 10:30 
GeneralRe: How to Draw Circles on GUI? Pin
Richard MacCutchan22-Mar-13 23:23
mveRichard MacCutchan22-Mar-13 23:23 
GeneralRe: How to Draw Circles on GUI? Pin
Gerry Schmitz23-Mar-13 9:01
mveGerry Schmitz23-Mar-13 9:01 
GeneralRe: How to Draw Circles on GUI? Pin
Richard MacCutchan23-Mar-13 22:18
mveRichard MacCutchan23-Mar-13 22:18 
GeneralRe: How to Draw Circles on GUI? Pin
Gerry Schmitz24-Mar-13 21:37
mveGerry Schmitz24-Mar-13 21:37 
GeneralRe: How to Draw Circles on GUI? Pin
Richard MacCutchan24-Mar-13 23:31
mveRichard MacCutchan24-Mar-13 23:31 
AnswerRe: How to Draw Circles on GUI? Pin
Abhinav S22-Mar-13 16:43
Abhinav S22-Mar-13 16:43 
AnswerRe: How to Draw Circles on GUI? Pin
cjb11025-Mar-13 0:14
cjb11025-Mar-13 0:14 
I don't know what VisualStudio it came with but there is a VisualBasic PowerPack that added the basic graphics objects to the toolbox for C# WinForm usage.

There's also multiple articles about creating LED controls on this site. Search

If you want to do it yourself, then you need to start looking into UserControls, and basically you create a class inheriting from UserControl and then you override the OnPaint event.

This is the OnPaint I did, its not great but it looks like a little led (with fade from colour to colour) which is all I wanted.
C#
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);

    Pen borderPen = new Pen(Color.Black);
    borderPen.Width = ClientSize.Width <= 16 ? 2 : 4;

    if (this.IsError)
    {
        using (Graphics g = e.Graphics)
        {
            SolidBrush brushError = new SolidBrush(ColorError);
            g.FillEllipse(brushError, 0, 0, ClientSize.Width, ClientSize.Height);

            g.DrawEllipse(borderPen, 0, 0, ClientSize.Width, ClientSize.Height);

            brushError.Dispose();
        }
    }
    else
    {
        Pen pen = new Pen(PercentageColor);

        SolidBrush brushInside = new SolidBrush(PercentageColor);

        int colorStepGradient = 1;
        byte colorGradient = 255 / 10;

        using (Graphics g = e.Graphics)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;

            int x = 0, y = 0;
            Color origPenColor = pen.Color;
            Color origBrushColor = brushInside.Color;
            int width = ClientSize.Width, height = ClientSize.Height;

            //draw ellipses at smaller and smaller sizes, stepping by _colorStepGradient
            for (; x <= width && y <= height; x += colorStepGradient, y += colorStepGradient, width -= 2 * colorStepGradient, height -= 2 * colorStepGradient)
            {
                g.DrawEllipse(pen, x, y, width, height);
                g.FillEllipse(brushInside, x, y, width, height);

                byte newR = pen.Color.R;
                byte newG = pen.Color.G;
                byte newB = pen.Color.B;

                //select the next colour stepping by _colorGradient
                if (pen.Color.R + colorGradient <= 255)
                    newR = (byte) (pen.Color.R + colorGradient);

                if (pen.Color.G + colorGradient <= 255)
                    newG = (byte) (pen.Color.G + colorGradient);

                if (pen.Color.B + colorGradient <= 255)
                    newB = (byte) (pen.Color.B + colorGradient);

                Color newcolor = Color.FromArgb(newR, newG, newB);
                pen.Color = newcolor;
                brushInside.Color = newcolor;
            }

            pen.Color = origPenColor;
            brushInside.Color = origBrushColor;

            g.DrawEllipse(borderPen, 0, 0, ClientSize.Width, ClientSize.Height);

            pen.Dispose();
            brushInside.Dispose();
        }
    }
    GraphicsPath path = new GraphicsPath();
    path.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
    this.Region = new Region(path);

    path.Dispose();
    borderPen.Dispose();
}

GeneralRe: How to Draw Circles on GUI? Pin
Stuck At Zero25-Mar-13 10:19
Stuck At Zero25-Mar-13 10:19 
GeneralRe: How to Draw Circles on GUI? Pin
cjb11025-Mar-13 21:37
cjb11025-Mar-13 21:37 
QuestionBest way to read string xml? [Solved] Pin
Boipelo21-Mar-13 7:58
Boipelo21-Mar-13 7:58 
AnswerRe: Best way to read string xml? Pin
Richard Deeming21-Mar-13 8:06
mveRichard Deeming21-Mar-13 8:06 
GeneralRe: Best way to read string xml? Pin
Boipelo21-Mar-13 8:12
Boipelo21-Mar-13 8:12 
GeneralRe: Best way to read string xml? Pin
Keld Ølykke22-Mar-13 0:27
Keld Ølykke22-Mar-13 0:27 
GeneralRe: Best way to read string xml? Pin
Boipelo22-Mar-13 5:32
Boipelo22-Mar-13 5:32 
AnswerRe: Best way to read string xml? Pin
PIEBALDconsult21-Mar-13 8:49
mvePIEBALDconsult21-Mar-13 8:49 
GeneralRe: Best way to read string xml? Pin
Boipelo21-Mar-13 9:19
Boipelo21-Mar-13 9:19 
AnswerRe: Best way to read string xml? Pin
jschell21-Mar-13 8:55
jschell21-Mar-13 8:55 
GeneralRe: Best way to read string xml? Pin
Boipelo21-Mar-13 9:14
Boipelo21-Mar-13 9:14 
GeneralRe: Best way to read string xml? Pin
jschell22-Mar-13 9:57
jschell22-Mar-13 9:57 
Questionform closing event not going to method Pin
MichCl21-Mar-13 4:30
MichCl21-Mar-13 4:30 
AnswerRe: form closing event not going to method Pin
PIEBALDconsult21-Mar-13 5:01
mvePIEBALDconsult21-Mar-13 5:01 
GeneralRe: form closing event not going to method Pin
MichCl21-Mar-13 5:31
MichCl21-Mar-13 5:31 
GeneralRe: form closing event not going to method Pin
PIEBALDconsult21-Mar-13 8:58
mvePIEBALDconsult21-Mar-13 8:58 
AnswerRe: form closing event not going to method Pin
Eddy Vluggen21-Mar-13 5:59
professionalEddy Vluggen21-Mar-13 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.