使用Graphics.DrawArc
方法时遇到一个小问题。使用时,它比实际尺寸短。我将此控件从找到here
我正在尝试将其转换为具有某些属性的UserControl
并展开它。问题是,当我设定每个百分比50%的百分比时,它会变短......
这是UserControl
在50%时的样子......它应该在圆圈的底部居中(蓝色)。我已尽力调整一切,但我现在迷失了。
这是我目前的代码......
Color _ProgressCompletedColor = SystemColors.MenuHighlight;
Color _ProgressNotCompleted = Color.LightGray;
Int32 _ProgressThickness = 2;
Single _ProgressCompleted = 25;
public AttuneProgressBar()
{
InitializeComponent();
}
public Single PercentageCompleted
{
get
{
return this._ProgressCompleted;
}
set
{
this._ProgressCompleted = value;
this.Invalidate();
}
}
public Int32 ProgressBarThickness
{
get
{
return this._ProgressThickness;
}
set
{
this._ProgressThickness = value;
this.Invalidate();
}
}
public Color ProgressNotCompletedColor
{
get
{
return this._ProgressNotCompleted;
}
set
{
this._ProgressNotCompleted = value;
this.Invalidate();
}
}
public Color ProgressCompletedColor
{
get
{
return this._ProgressCompletedColor;
}
set
{
this._ProgressCompletedColor = value;
this.Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
// Call the OnPaint method of the base class.
base.OnPaint(e);
DrawProgress(e.Graphics, new Rectangle(new Point(1,1), new Size(this.ClientSize.Width - 3, this.ClientSize.Height - 3)), PercentageCompleted);
}
private void DrawProgress(Graphics g, Rectangle rec, Single percentage)
{
Single progressAngle = (360 / 100 * percentage);
Single remainderAngle = 360 - progressAngle;
try
{
using (Pen progressPen = new Pen(ProgressCompletedColor, ProgressBarThickness), remainderPen = new Pen(ProgressNotCompletedColor, ProgressBarThickness))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.DrawArc(progressPen, rec, -90, progressAngle);
g.DrawArc(remainderPen, rec, progressAngle - 90, remainderAngle);
}
}
catch (Exception exc) { }
}
}
答案 0 :(得分:2)
您正在使用整数计算角度。当你这样做时:
mean
意味着
temp <- list.files(pattern="chr*.txt")
lst <- lapply(temp, read.table, header=FALSE)
Reduce('+', lst)/length(lst)
这当然会导致错误。如果你想继续使用整数,有一个简单的解决方法:
angle = 360 / 100 * percentage;
这种方式在乘法之前不会向下舍入。或者你可以一直使用浮动:
angle = 3 * percentage;