Styling Information:
The ForeColor and Backcolor properties have an effect only if
visual styles are disabled for the system or the application.
Style property:
- Visual styles disabled:
Continuous and Blocks are available. Marquee is the same as Blocks.
- Visual styles enabled:
Marquee and Continuous is available. Blocks is the same as Continuous.
It could be because of Visual Styles? Also I do not see a Elapsed Event handler :S Is it not Tick? The only Event for the TimerControl for me is the Tick Event.
C# Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsForm
{
public class ProgressBarCustom : ProgressBar
{
public ProgressBarCustom()
{
this.Style = ProgressBarStyle.Blocks;
this.Visible = true;
}
public ProgressBarCustom(ProgressBarStyle Style)
{
this.Style = Style;
this.Visible = true;
}
/* Un-comment to disable Theming of the Bar..
protected override void CreateHandle()
{
base.CreateHandle();
try
{
SetWindowTheme(this.Handle, "", "");
}
catch
{
}
}
*/
[System.Runtime.InteropServices.DllImport("uxtheme.dll")]
private static extern int SetWindowTheme(IntPtr hwnd, string appname, string idlist);
}
}
C# Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
//timer1.Stop();
//timer1.Enabled = false;
progressBarCustom1.PerformStep();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void progressBarCustom1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 5000;
timer1.Start();
progressBarCustom1.Step = 10;
if (progressBarCustom1.Style == ProgressBarStyle.Marquee)
{
progressBarCustom1.Style = ProgressBarStyle.Blocks;
}
else
{
progressBarCustom1.Style = ProgressBarStyle.Marquee;
}
}
}
}