Click here to Skip to main content
15,905,420 members
Home / Discussions / C#
   

C#

 
Questionabout the time period Pin
lightofheaven21-Mar-13 17:44
lightofheaven21-Mar-13 17:44 
AnswerRe: about the time period Pin
Boipelo21-Mar-13 21:07
Boipelo21-Mar-13 21:07 
QuestionHow to Draw Circles on GUI? Pin
Stuck At Zero21-Mar-13 10:32
Stuck At Zero21-Mar-13 10:32 
JokeRe: How to Draw Circles on GUI? Pin
Matt T Heffron21-Mar-13 10:54
professionalMatt T Heffron21-Mar-13 10:54 
AnswerRe: How to Draw Circles on GUI? Pin
Richard MacCutchan21-Mar-13 23:41
mveRichard MacCutchan21-Mar-13 23:41 
GeneralRe: How to Draw Circles on GUI? Pin
Stuck At Zero22-Mar-13 5:33
Stuck At Zero22-Mar-13 5:33 
GeneralRe: How to Draw Circles on GUI? Pin
Richard MacCutchan22-Mar-13 8:00
mveRichard MacCutchan22-Mar-13 8:00 
GeneralRe: How to Draw Circles on GUI? Pin
Stuck At Zero22-Mar-13 10:05
Stuck At Zero22-Mar-13 10:05 
GeneralRe: How to Draw Circles on GUI? Pin
Gerry Schmitz22-Mar-13 14:39
mveGerry Schmitz22-Mar-13 14:39 
GeneralRe: How to Draw Circles on GUI? Pin
Stuck At Zero22-Mar-13 14:56
Stuck At Zero22-Mar-13 14:56 
GeneralRe: How to Draw Circles on GUI? Pin
Gerry Schmitz22-Mar-13 17:43
mveGerry Schmitz22-Mar-13 17:43 
GeneralRe: How to Draw Circles on GUI? Pin
Stuck At Zero25-Mar-13 10:28
Stuck At Zero25-Mar-13 10:28 
GeneralRe: How to Draw Circles on GUI? Pin
Richard MacCutchan22-Mar-13 23:19
mveRichard MacCutchan22-Mar-13 23:19 
GeneralRe: How to Draw Circles on GUI? Pin
Gerry Schmitz23-Mar-13 8:57
mveGerry Schmitz23-Mar-13 8:57 
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 

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.