Skip to content

Commit 40c9118

Browse files
committed
#12 Exchanged ProgressBar with custom implementation
1 parent 7b5a90b commit 40c9118

12 files changed

+650
-40
lines changed
Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Windows.Forms;
4+
using System.Drawing;
5+
6+
namespace ColorProgressBar
7+
{
8+
[Description("Color Progress Bar")]
9+
[ToolboxBitmap(typeof(ProgressBar))]
10+
[Designer(typeof(ColorProgressBarDesigner))]
11+
public class ColorProgressBar : System.Windows.Forms.Control
12+
{
13+
14+
private int _Value = 0;
15+
private int _Minimum = 0;
16+
private int _Maximum = 100;
17+
private int _Step = 10;
18+
19+
private Color _BarColor = Color.FromArgb(255, 128, 128);
20+
private Color _BorderColor = Color.Black;
21+
22+
public enum FillStyles
23+
{
24+
Solid,
25+
Dashed
26+
}
27+
28+
public ColorProgressBar()
29+
{
30+
base.Size = new Size(150, 15);
31+
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer, true);
32+
}
33+
34+
[Description("ColorProgressBar color")]
35+
[Category("ColorProgressBar")]
36+
public Color BarColor
37+
{
38+
get
39+
{
40+
return _BarColor;
41+
}
42+
set
43+
{
44+
_BarColor = value;
45+
this.Invalidate();
46+
}
47+
}
48+
49+
[Description("The current value for the ColorProgressBar, in the range specified by the Minimum and Maximum properties.")]
50+
[Category("ColorProgressBar")]
51+
[RefreshProperties(RefreshProperties.All)]
52+
public int Value
53+
{
54+
get
55+
{
56+
return _Value;
57+
}
58+
set
59+
{
60+
if (value < _Minimum)
61+
{
62+
throw new ArgumentException("'" + value + "' is not a valid value for 'Value'.\n" +
63+
"'Value' must be between 'Minimum' and 'Maximum'.");
64+
}
65+
66+
if (value > _Maximum)
67+
{
68+
throw new ArgumentException("'" + value + "' is not a valid value for 'Value'.\n" +
69+
"'Value' must be between 'Minimum' and 'Maximum'.");
70+
}
71+
72+
_Value = value;
73+
this.Invalidate();
74+
}
75+
}
76+
77+
[Description("The lower bound of the range this ColorProgressbar is working with.")]
78+
[Category("ColorProgressBar")]
79+
[RefreshProperties(RefreshProperties.All)]
80+
public int Minimum
81+
{
82+
get
83+
{
84+
return _Minimum;
85+
}
86+
set
87+
{
88+
_Minimum = value;
89+
90+
if (_Minimum > _Maximum)
91+
_Maximum = _Minimum;
92+
if (_Minimum > _Value)
93+
_Value = _Minimum;
94+
95+
this.Invalidate();
96+
}
97+
}
98+
99+
[Description("The uppper bound of the range this ColorProgressbar is working with.")]
100+
[Category("ColorProgressBar")]
101+
[RefreshProperties(RefreshProperties.All)]
102+
public int Maximum
103+
{
104+
get
105+
{
106+
return _Maximum;
107+
}
108+
set
109+
{
110+
_Maximum = value;
111+
112+
if (_Maximum < _Value)
113+
_Value = _Maximum;
114+
if (_Maximum < _Minimum)
115+
_Minimum = _Maximum;
116+
117+
this.Invalidate();
118+
}
119+
}
120+
121+
[Description("The amount to jump the current value of the control by when the Step() method is called.")]
122+
[Category("ColorProgressBar")]
123+
public int Step
124+
{
125+
get
126+
{
127+
return _Step;
128+
}
129+
set
130+
{
131+
_Step = value;
132+
this.Invalidate();
133+
}
134+
}
135+
136+
[Description("The border color of ColorProgressBar")]
137+
[Category("ColorProgressBar")]
138+
public Color BorderColor
139+
{
140+
get
141+
{
142+
return _BorderColor;
143+
}
144+
set
145+
{
146+
_BorderColor = value;
147+
this.Invalidate();
148+
}
149+
}
150+
151+
///
152+
/// <summary>Call the PerformStep() method to increase the value displayed by the amount set in the Step property</summary>
153+
///
154+
public void PerformStep()
155+
{
156+
if (_Value < _Maximum)
157+
_Value += _Step;
158+
else
159+
_Value = _Maximum;
160+
161+
this.Invalidate();
162+
}
163+
164+
///
165+
/// <summary>Call the PerformStepBack() method to decrease the value displayed by the amount set in the Step property</summary>
166+
///
167+
public void PerformStepBack()
168+
{
169+
if (_Value > _Minimum)
170+
_Value -= _Step;
171+
else
172+
_Value = _Minimum;
173+
174+
this.Invalidate();
175+
}
176+
177+
///
178+
/// <summary>Call the Increment() method to increase the value displayed by an integer you specify</summary>
179+
///
180+
public void Increment(int value)
181+
{
182+
if (_Value < _Maximum)
183+
_Value += value;
184+
else
185+
_Value = _Maximum;
186+
187+
this.Invalidate();
188+
}
189+
190+
//
191+
// <summary>Call the Decrement() method to decrease the value displayed by an integer you specify</summary>
192+
//
193+
public void Decrement(int value)
194+
{
195+
if (_Value > _Minimum)
196+
_Value -= value;
197+
else
198+
_Value = _Minimum;
199+
200+
this.Invalidate();
201+
}
202+
203+
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
204+
{
205+
//
206+
// Check for value
207+
//
208+
if (_Maximum == _Minimum || _Value == 0)
209+
{
210+
// Draw border only and exit;
211+
DrawBorder(e.Graphics);
212+
return;
213+
}
214+
215+
//
216+
// The following is the width of the bar. This will vary with each value.
217+
//
218+
int fillWidth = (this.Width * _Value) / (_Maximum - _Minimum);
219+
220+
//
221+
// Rectangles for upper and lower half of bar
222+
//
223+
Rectangle rect = new Rectangle(0, 0, fillWidth, this.Height);
224+
225+
//
226+
// The brush
227+
//
228+
SolidBrush brush = new SolidBrush(_BarColor);
229+
e.Graphics.FillRectangle(brush, rect);
230+
brush.Dispose();
231+
232+
//
233+
// Draw border and exit
234+
DrawBorder(e.Graphics);
235+
}
236+
237+
protected void DrawBorder(Graphics g)
238+
{
239+
Rectangle borderRect = new Rectangle(0, 0,
240+
ClientRectangle.Width - 1, ClientRectangle.Height - 1);
241+
g.DrawRectangle(new Pen(_BorderColor, 1), borderRect);
242+
}
243+
}
244+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{739E6F07-E688-4D16-8FDF-7472E7F0FEA0}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<RootNamespace>ColorProgressBar</RootNamespace>
10+
<AssemblyName>ColorProgressBar</AssemblyName>
11+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<Deterministic>true</Deterministic>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<PropertyGroup>
35+
<StartupObject />
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Design" />
41+
<Reference Include="System.Xml.Linq" />
42+
<Reference Include="System.Data.DataSetExtensions" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Data" />
45+
<Reference Include="System.Deployment" />
46+
<Reference Include="System.Drawing" />
47+
<Reference Include="System.Windows.Forms" />
48+
<Reference Include="System.Xml" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Compile Include="ColorProgressBar.cs">
52+
<SubType>Component</SubType>
53+
</Compile>
54+
<Compile Include="ColorProgressBarDesigner.cs" />
55+
<Compile Include="Properties\AssemblyInfo.cs" />
56+
<EmbeddedResource Include="Properties\Resources.resx">
57+
<Generator>ResXFileCodeGenerator</Generator>
58+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
59+
<SubType>Designer</SubType>
60+
</EmbeddedResource>
61+
<Compile Include="Properties\Resources.Designer.cs">
62+
<AutoGen>True</AutoGen>
63+
<DependentUpon>Resources.resx</DependentUpon>
64+
</Compile>
65+
<None Include="Properties\Settings.settings">
66+
<Generator>SettingsSingleFileGenerator</Generator>
67+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
68+
</None>
69+
<Compile Include="Properties\Settings.Designer.cs">
70+
<AutoGen>True</AutoGen>
71+
<DependentUpon>Settings.settings</DependentUpon>
72+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
73+
</Compile>
74+
</ItemGroup>
75+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Collections;
2+
3+
namespace ColorProgressBar
4+
{
5+
internal class ColorProgressBarDesigner : System.Windows.Forms.Design.ControlDesigner
6+
{
7+
public ColorProgressBarDesigner()
8+
{}
9+
10+
/// <summary>Clean up some unnecessary properties</summary>
11+
protected override void PostFilterProperties(IDictionary Properties)
12+
{
13+
Properties.Remove("AllowDrop");
14+
Properties.Remove("BackgroundImage");
15+
Properties.Remove("ContextMenu");
16+
Properties.Remove("FlatStyle");
17+
Properties.Remove("Image");
18+
Properties.Remove("ImageAlign");
19+
Properties.Remove("ImageIndex");
20+
Properties.Remove("ImageList");
21+
Properties.Remove("Text");
22+
Properties.Remove("TextAlign");
23+
}
24+
}
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ColorProgressBar")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ColorProgressBar")]
13+
[assembly: AssemblyCopyright("Copyright © 2021")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("739e6f07-e688-4d16-8fdf-7472e7f0fea0")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy