[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2930
  • Last Modified:

Creating a circular progress bar...

I want to make a custom progress bar which would be almost a complete circle.

An example in c++ is http://www.codeguru.com/cpp/misc/misc/system/article.php/c11679/

Is this easily doable with c#?

Thanks
0
rushtheweb
Asked:
rushtheweb
  • 4
  • 2
  • 2
1 Solution
 
AlexFMCommented:
Windows hooks are not part of .NET. This can be done in C#, but 99% of code must be written using API PInvoke code. I think it can be done better in C++/CLI, which allows direct API calls without PInvoke.
0
 
AlexFMCommented:
Actually, you can write C++/CLI Class Library, add files MousePrg.cpp, MousePrg.h, MousePrgVars.h, and MousePrgHook.h to it and use CMousePrg class directly from C++/CLI code.
0
 
rushthewebAuthor Commented:
Im not looking to have it recreated like that example (mouse following and what not); Im just hoping to make something similar to put on a form for not only a visual element but also as a space saver. I appreciate your comments! :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dstanley9Commented:
Here's the start of a custom control to do this.  It's pretty crude, but it gives you a place to start:

public partial class CircularProgressBar : Control
{
    public CircularProgressBar()
    {
        InitializeComponent();
    }

    private int _MinValue;
    private int _MaxValue;
    private int _Value;

    public int MinValue
    {
        get { return _MinValue; }
        set { _MinValue = value; }
    }
    public int MaxValue
    {
        get { return _MaxValue; }
        set { _MaxValue = value; }
    }
    public int Value
    {
        get { return _Value; }
        set { _Value = value; }
    }

    protected override void OnPaint(PaintEventArgs pe)
    {
        Graphics g = pe.Graphics;

        // CUSTOMIZATION: Width of pen is hard coded
        Rectangle rec = Rectangle.Inflate(this.ClientRectangle, -10, -10);

        // CUSTOMIZATION: Allow user to choose color and width
        Pen pen = new Pen(Color.Red,10);

        // CUSTOMIZATION: Allow user to choose starting point
        float startAngle = 270.0f;  // Angle of due North clockwise from x-axis
     
        // Percentage of a complete circle to draw
        float percent = (float)(_Value - _MinValue) / (float)(_MaxValue - _MinValue);
       
        // CUSTOMIZATION: Allow user to choose direction (CW or CCW)
        // Draws a clockwise arc starting from due north
        g.DrawArc(pen,rec,startAngle,360.0f * percent);

        // Calling the base class OnPaint
        base.OnPaint(pe);
    }
}
0
 
rushthewebAuthor Commented:
Awesome, ill give it a shot... can you tell me what to define pe as?

Thanks
0
 
rushthewebAuthor Commented:
Scratch that I wasnt paying attention! :)
0
 
rushthewebAuthor Commented:
Awesome, it seems to be working. I will have to play with it and figure out how to do a border to make it look more like a progress bar and change the direction to counter clockwise and then I think its perfect! If you have any more tips toward my goal I would really appreciate them. :)
0
 
dstanley9Commented:
To go counterclockwise, just use a negative 4th parameter to DrawArc:

g.DrawArc(pen,rec,startAngle,-360.0f * percent);
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now