 |
|
|
 |
|
 |
Hi there. Like coyotelapa, I also made some improvements and bug fixes to the code:
1. Placed a Timer within the user control allowing the progress disk to animate without needing to add a Timer to the form.
2. Added the Animate property to interact with the Timer. Animate is a boolean and when set to True, the Timer will be enabled and will run and raise Elapsed events. When set to False, the Timer will be disabled and the progress disk's value will stay the same.
3. Added the TimeDelay property to interact with the Timer. TimeDelay sets the amount of time, in milliseconds, before the Elapsed event is raised in the Timer, if the Timer is enabled.
4. Changed how the value changes when the Elapsed event is raised, thus allowing the progress disk to be animated without any bugs, mess-ups, or glitches with any number of slices. Before, because the constant 12 was used, if the SliceCount was anything different, certain slices would be skipped or repeated.
5. Organized the control's properties into categories, and added descriptions.
6. Updated the project to .NET Framework 4. The .cs files will still open in previous versions of Visual Studio though...
This is the first time I've worked with C#. I've been a VB.NET developer for years, but I decided it's time for me to move over to C#.
Overall, this is a very nice control. I'm happy to have come across it. With these refinements, I hope to make it even better.
I posted the new code on my website, rather than making a super-long message here: You can download the project here:
https://sites.google.com/site/jaykerh/ProgressDisk.zip?attredirects=0&d=1[^]
Jayke R. Huempfner
Yes, I do spell it with a 'y'...
|
|
|
|
 |
|
 |
Hola Amr,
Excelente trabajo. Te cuento que le hice una modificación al control para que se comporte como el ProgressBar de WPF, a través de una propiedad llamada IsIndeterminate que permite que la barra se mueva sin necesidad de asignarle valores manualmente.
Deseo saber como hago para enviarte el código corregido.
Saludos
Carlos Gutiérrez
El conocimiento es libre y debe ser de todos
|
|
|
|
 |
|
 |
This is a very useful control and very well done! Thanks for that, Amr.
I realize this may be a very slight complaint, but if you change the BorderStyle property of the ProgressDisk control to "FixedSingle", you'll notice that the drawn ProgressDisk is clipped on the bottom and right sides. In contrast, the top and left sides appear to have a single pixel cushion from the border. I'm sure it's a relatively simple fix, but I thought I'd point it out, since you can see the clipping even without the border present. Kinda looks like the client area isn't quite large enough for what you draw.
Again, thanks for the control!
Matt
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Amr Elsehemy® wrote: Thank you very much made my day
No problem
Amr Elsehemy® wrote: custom controls check these DigitalCounter[^] and SuperToolTip[^]
Why not post them up here on Code Project, as well?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
 |
|
 |
There was a competition that I liked to join was for an xbox.
|
|
|
|
 |
|
 |
Just so you know: for the copyright notice in your assembly info to be valid it needs to have the word Copyright or the (c) symbol, the year(s), and the Author's name (you're missing this part). You may also want to specify the license, like Copyright (c) 2006 Pixelated. All rights reserved. Something like that. If you don't really care if people use your code it's no problem, but if you ever wanted to sue for copyright infringement, that may be a problem.
-Tyler Menezes
-Tyler Menezes
CEO and Chairman of Programs and Websites and MyWebsFree.com
"If a plane is on a convayer belt moving backwards at the same speed that it moves fowards, will it take off?"
|
|
|
|
 |
|
 |
Thank you very much for that advice ,
I would use it later, but this control was made to be useful for others to learn and share code . I dont mind any one using the code for his own its a free control.
Thank you.
|
|
|
|
 |
|
 |
The subject says it all but anyways: it rocks! I'm going to use it because the GUI is awesome. Look for NoFooling 2.0, it will have it in it.
-Tyler Menezes
CEO and Chairman of Programs and Websites and MyWebsFree.com
"If a plane is on a convayer belt moving backwards at the same speed that it moves fowards, will it take off?"
|
|
|
|
 |
|
 |
thnks
but sorry what is NoFooling2.0 a control? is there any links?
thnks
|
|
|
|
 |
|
 |
Sorry, should have said. It's an educational program. www.nofooling.org.
-Tyler Menezes
CEO and Chairman of Programs and Websites and MyWebsFree.com
"If a plane is on a convayer belt moving backwards at the same speed that it moves fowards, will it take off?"
|
|
|
|
 |
|
 |
Great idea on the control!
In trying it out, I thought, "Why not include the timer within the control itself, so the developer doesn't have to add a timer to his/her form to make it work?" To do so, I added a timer called 'tmrDisk' and a couple of new properties. One property (SweepRate) to set the rate at wich the value changes. It really just sets the interval on the 'tmrDisk'. The other (IsRunning) turns the timer on or off. I'd rather have used the control's Enabled property, but I'm a complete C# novice and when I tried to override the Enabled property I ran into trouble (ideas welcome here):
private int sweepRate;
[DefaultValue(100)]
public int SweepRate
{
get { return sweepRate; }
set {
sweepRate = value;
if (sweepRate < 10) sweepRate = 100;
tmrDisk.Interval = sweepRate;
}
}
private bool isRunning;
[DefaultValue(true)]
public bool IsRunning
{
get { return isRunning; }
set {
isRunning = value;
tmrDisk.Enabled = IsRunning;
}
}
And the Tick event handler for the timer:
private void tmrDisk_Tick(object sender, EventArgs e)
{
this.value = (this.Value + 1) % sliceCount;
Render();
}
cheers,
Andrew.
|
|
|
|
 |
|
 |
Hello,
first: nice Control
second: when you increase the SliceCount more than 12 (eg. 60) your Control doesn't work correctly.
(there are some spaces between the first and the last slices and the the active slice-change doesn't shown the right count way)
Best Regards
Tim
|
|
|
|
 |
|
 |
Hi,
this issue can be fixed by changing frmTest.timer1_Tick like this:
OLD:
private void timer1_Tick(object sender, EventArgs e)
{
progressDisk1.Value = (progressDisk1.Value + 1) % 12;
}
NEW:
private void timer1_Tick(object sender, EventArgs e)
{
progressDisk1.Value = (progressDisk1.Value + 1) % progressDisk1.SliceCount;
}
However, this is just a quick fix;). Control should be modifed so it does not depend on how external code modifies ProgressDisk.Value.
Or maybe ProgressDisk.Value should even be made private property and be hidden from external code and new method is introduced which would do exactly what timer1_Tick does at the moment?
For example:
public void DoAnimationStep()
{
this.Value = (this.Value + 1) % this.SliceCount;
}
Best Regards
|
|
|
|
 |
|
 |
Hi,
I'm sending you slightly improved version of your control.
Changes:
1. I've introduced SliceCount property which determines number of slices shown
2. Fixed the "Resize problem"
3. I've also removed creation of new graphic paths every time Render() is called
Regards
Code :
[DefaultProperty("BlockSize")]
public partial class ProgressDisk : UserControl
{
private GraphicsPath bkGroundPath1 = new GraphicsPath();
private GraphicsPath bkGroundPath2 = new GraphicsPath();
private GraphicsPath valuePath = new GraphicsPath();
private GraphicsPath freGroundPath = new GraphicsPath();
private int sliceCount;
private int value;
[DefaultValue(0)]
public int Value
{
get { return value; }
set
{
this.value = value;
Render();
}
}
private Color backGrndColor = Color.White;
[DefaultValue(typeof (Color), "White")]
public Color BackGroundColor
{
get { return backGrndColor; }
set
{
backGrndColor = value;
Render();
}
}
private Color activeforeColor1 = Color.Blue;
[DefaultValue(typeof (Color), "Blue")]
public Color ActiveForeColor1
{
get { return activeforeColor1; }
set
{
activeforeColor1 = value;
Render();
}
}
private Color activeforeColor2 = Color.LightBlue;
[DefaultValue(typeof (Color), "LightBlue")]
public Color ActiveForeColor2
{
get { return activeforeColor2; }
set
{
activeforeColor2 = value;
Render();
}
}
private Color inactiveforeColor1 = Color.Green;
[DefaultValue(typeof (Color), "Green")]
public Color InactiveForeColor1
{
get { return inactiveforeColor1; }
set
{
inactiveforeColor1 = value;
Render();
}
}
private Color inactiveforeColor2 = Color.LightGreen;
[DefaultValue(typeof (Color), "LightGreen")]
public Color InactiveForeColor2
{
get { return inactiveforeColor2; }
set
{
inactiveforeColor2 = value;
Render();
}
}
private int size = 50;
[DefaultValue(50)]
public int SquareSize
{
get { return size; }
set
{
size = value;
Size = new Size(size, size);
}
}
private float blockRatio = .4f;
private BlockSize bs = BlockSize.Small;
[DefaultValue(typeof (BlockSize), "Small")]
public BlockSize BlockSize
{
get { return bs; }
set
{
bs = value;
switch (bs)
{
case BlockSize.XSmall:
blockRatio = 0.49f;
break;
case BlockSize.Small:
blockRatio = 0.4f;
break;
case BlockSize.Medium:
blockRatio = 0.3f;
break;
case BlockSize.Large:
blockRatio = 0.2f;
break;
case BlockSize.XLarge:
blockRatio = 0.1f;
break;
case BlockSize.XXLarge:
blockRatio = 0.01f;
break;
default:
break;
}
}
}
[DefaultValue(12)]
public int SliceCount
{
get { return sliceCount; }
set { sliceCount = value; }
}
public ProgressDisk()
{
InitializeComponent();
// CheckForIllegalCrossThreadCalls = false;
Render();
}
private Region region = new Region();
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
region = new Region(ClientRectangle);
if (backGrndColor == Color.Transparent)
{
region.Exclude(bkGroundPath2);
Region = region;
}
e.Graphics.FillPath(new SolidBrush(backGrndColor), bkGroundPath1);
e.Graphics.FillPath(
new LinearGradientBrush(new Rectangle(0, 0, size, size), inactiveforeColor1, inactiveforeColor2,
value*360/12, true), valuePath);
e.Graphics.FillPath(
new LinearGradientBrush(new Rectangle(0, 0, size, size), activeforeColor1, activeforeColor2,
value*360/12, true), freGroundPath);
e.Graphics.FillPath(new SolidBrush(backGrndColor), bkGroundPath2);
base.OnPaint(e);
}
private void Render()
{
// bkGroundPath1 = new GraphicsPath();
// bkGroundPath2 = new GraphicsPath();
// valuePath = new GraphicsPath();
// freGroundPath = new GraphicsPath();
bkGroundPath1.Reset();
bkGroundPath2.Reset();
valuePath.Reset();
freGroundPath.Reset();
bkGroundPath1.AddPie(new Rectangle(0, 0, size, size), 0, 360);
//just in case...
if (sliceCount == 0)
{
sliceCount = 12;
}
float sliceAngle = 360/sliceCount;
float sweepAngle = sliceAngle - 5;
for (int i = 0; i < sliceCount; i++)
{
if (value != i)
{
valuePath.AddPie(0, 0, size, size, i*sliceAngle, sweepAngle);
}
}
bkGroundPath2.AddPie(
(size/2 - size*blockRatio), (size/2 - size*blockRatio),
(blockRatio*2*size), (blockRatio*2*size), 0, 360);
freGroundPath.AddPie(new Rectangle(0, 0, size, size), value * sliceAngle, sweepAngle);
Invalidate();
}
protected override void OnSizeChanged(EventArgs e)
{
size = Math.Max(Width, Height);
Size = new Size(size, size);
Render();
base.OnSizeChanged(e);
}
protected override void OnResize(EventArgs e)
{
size = Math.Max(Width, Height);
Size = new Size(size, size);
Render();
base.OnResize(e);
}
}
|
|
|
|
 |
|
 |
Thnk u for helping
i posted the changes
|
|
|
|
 |
|
 |
You're welcome;)
Great control btw
Regards
|
|
|
|
 |
|
 |
Hi ,
great work man
There's a slight problem when resizing - the upper left corner seems a bit smaller
Cheers,
Tzvi
|
|
|
|
 |
|
 |
Yes i tried dealing with that problem but the addPie function only accepts a rectangle object not a rectangleF object which differs in that pixel when an odd size is used because of integer truncation i ll try to find a fix for that. thank u
|
|
|
|
 |
|
 |
You might wanna enable anitaliasing to get rid of those nasty jagged edges
|
|
|
|
 |
|
|
 |
|
 |
Any block size combined with a transparent background results in a transparent background and a XXL Block Size...
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
 |
|
 |
Yes as I mentioned up it was a 3 layer pie charts
if the background is Transparent that means no background layers so the pizza slices left without a cover.
|
|
|
|
 |