自定义的控件是一个进度条,运行时,并不会显示我重绘的效果,只是系统自带的进度条,这是为什么
6 个解决方案
#1
会不会是运行起来之后又重新加载了 默认的设置
#2
那怎么不加载默认的设置?
#3
没写好而已。
#4
这个确实是没有写好,重载的地方出现了问题
#5
public partial class opopo : ProgressBar
{
public opopo()
{
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
public opopo(IContainer container)
{
container.Add(this);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
Pen p = new Pen(Color.Gainsboro, 1);
Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
e.Graphics.DrawRectangle(p, bounds);
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, bounds.Width - 2, bounds.Height - 2);
bounds.Height -= 4;
bounds.Width = ((int)(bounds.Width * (((double)(base.Value - base.Minimum)) / ((double)(base.Maximum - base.Minimum))))) - 4;
SolidBrush brush = new SolidBrush(this.ForeColor);
e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);
int percentage = base.Value - base.Minimum;
StringFormat strFormat = new StringFormat();
string percentageText = percentage.ToString() + "%";
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
strFormat.FormatFlags = StringFormatFlags.LineLimit;
strFormat.Trimming = StringTrimming.None;
SolidBrush objBrush = new SolidBrush(Color.Black);
e.Graphics.DrawString(percentageText, new Font("Arial", 10), objBrush, this.ClientRectangle, strFormat);
}
}
代码不应该有问题啊
{
public opopo()
{
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
public opopo(IContainer container)
{
container.Add(this);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
Pen p = new Pen(Color.Gainsboro, 1);
Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
e.Graphics.DrawRectangle(p, bounds);
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, bounds.Width - 2, bounds.Height - 2);
bounds.Height -= 4;
bounds.Width = ((int)(bounds.Width * (((double)(base.Value - base.Minimum)) / ((double)(base.Maximum - base.Minimum))))) - 4;
SolidBrush brush = new SolidBrush(this.ForeColor);
e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);
int percentage = base.Value - base.Minimum;
StringFormat strFormat = new StringFormat();
string percentageText = percentage.ToString() + "%";
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
strFormat.FormatFlags = StringFormatFlags.LineLimit;
strFormat.Trimming = StringTrimming.None;
SolidBrush objBrush = new SolidBrush(Color.Black);
e.Graphics.DrawString(percentageText, new Font("Arial", 10), objBrush, this.ClientRectangle, strFormat);
}
}
代码不应该有问题啊
#6
方法是对的,OnPaint里面的就不知道有不有问题了,
建议打个断点在OnPaint调试下,看每次进度改变时,有没执行你重写的OnPaint方法,界面上感觉进了基类的OnPaint
自绘控件网上一搜应该很多例子。
建议打个断点在OnPaint调试下,看每次进度改变时,有没执行你重写的OnPaint方法,界面上感觉进了基类的OnPaint
自绘控件网上一搜应该很多例子。
#1
会不会是运行起来之后又重新加载了 默认的设置
#2
那怎么不加载默认的设置?
#3
没写好而已。
#4
这个确实是没有写好,重载的地方出现了问题
#5
public partial class opopo : ProgressBar
{
public opopo()
{
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
public opopo(IContainer container)
{
container.Add(this);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
Pen p = new Pen(Color.Gainsboro, 1);
Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
e.Graphics.DrawRectangle(p, bounds);
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, bounds.Width - 2, bounds.Height - 2);
bounds.Height -= 4;
bounds.Width = ((int)(bounds.Width * (((double)(base.Value - base.Minimum)) / ((double)(base.Maximum - base.Minimum))))) - 4;
SolidBrush brush = new SolidBrush(this.ForeColor);
e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);
int percentage = base.Value - base.Minimum;
StringFormat strFormat = new StringFormat();
string percentageText = percentage.ToString() + "%";
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
strFormat.FormatFlags = StringFormatFlags.LineLimit;
strFormat.Trimming = StringTrimming.None;
SolidBrush objBrush = new SolidBrush(Color.Black);
e.Graphics.DrawString(percentageText, new Font("Arial", 10), objBrush, this.ClientRectangle, strFormat);
}
}
代码不应该有问题啊
{
public opopo()
{
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
public opopo(IContainer container)
{
container.Add(this);
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
Pen p = new Pen(Color.Gainsboro, 1);
Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
e.Graphics.DrawRectangle(p, bounds);
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, bounds.Width - 2, bounds.Height - 2);
bounds.Height -= 4;
bounds.Width = ((int)(bounds.Width * (((double)(base.Value - base.Minimum)) / ((double)(base.Maximum - base.Minimum))))) - 4;
SolidBrush brush = new SolidBrush(this.ForeColor);
e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);
int percentage = base.Value - base.Minimum;
StringFormat strFormat = new StringFormat();
string percentageText = percentage.ToString() + "%";
strFormat.Alignment = StringAlignment.Center;
strFormat.LineAlignment = StringAlignment.Center;
strFormat.FormatFlags = StringFormatFlags.LineLimit;
strFormat.Trimming = StringTrimming.None;
SolidBrush objBrush = new SolidBrush(Color.Black);
e.Graphics.DrawString(percentageText, new Font("Arial", 10), objBrush, this.ClientRectangle, strFormat);
}
}
代码不应该有问题啊
#6
方法是对的,OnPaint里面的就不知道有不有问题了,
建议打个断点在OnPaint调试下,看每次进度改变时,有没执行你重写的OnPaint方法,界面上感觉进了基类的OnPaint
自绘控件网上一搜应该很多例子。
建议打个断点在OnPaint调试下,看每次进度改变时,有没执行你重写的OnPaint方法,界面上感觉进了基类的OnPaint
自绘控件网上一搜应该很多例子。