DrawStorage()でストレージ(画像A)を作成します。私はFillWater()を使用してストレージを満たすために。私は画像Cのように0-100%(空のフル)の水準で水を満たしたかったのですが、画像BのようにFillWater()から現在の出力が生成されました。 C?難易度は3D(写真C)のようにストレージを満たす方法ですC#で3Dチューブの下半分を描く方法
私の英語が良くない場合は、私は専門家であるあなたの助けを願っています、ありがとう。
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
Graphics g = pe.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
this.DrawBar(g, this.ForeColor);
}
private void DrawBar(Graphics g, Color foreColor)
{
bool outLine = this._outLineColor != Color.Transparent;
Rectangle bound = this.ClientRectangle;
bound.Inflate(-20, -20);
DrawStorage(g, bound, new Size(4, 10), Color.FromArgb(this.Alpha, foreColor), this.OutLineColor, outLine);
if (this.Value > this.Minimum && this.Value <= this.Maximum)
{
float barValue = bound.Height * ((this.Value - this.Minimum)/(this.Maximum - this.Minimum));
RectangleF valueBound = RectangleF.FromLTRB(bound.Left, bound.Bottom - barValue, bound.Right, bound.Bottom);
FillWater(g, valueBound, new Size(4, 10), Color.FromArgb(this.Alpha, this.BarColor), this.OutLineColor, outLine);
if (this._showValue && valueBound.Height > 20)
{
g.SmoothingMode = SmoothingMode.AntiAlias;
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
g.DrawString(this._value.ToString("F2"), this.Font, Brushes.Black, valueBound, format);
format.Dispose();
}
}
}
public static void DrawStorage(Graphics g, RectangleF front, SizeF depth, Color fillColor, Color borderColor, bool outLine)
{
if (front.Width <= 0 || front.Height <= 0)
return;
// Make Back Side Area
RectangleF aback = front;
// Make Depth
aback.X += depth.Width;
aback.Y -= depth.Height;
// Create Top and Bottom Plane.
RectangleF leftPlane;
RectangleF rightPlane;
// Create Graphics Object
GraphicsPath gp = new GraphicsPath();
rightPlane = new RectangleF(front.Width, front.Y, front.X, front.Height);
leftPlane = new RectangleF(front.X, front.Y, front.X, front.Height);
// Brush
SolidBrush brush = new SolidBrush(fillColor);
// Border Pen
Pen borderPen = new Pen(borderColor);
/***************
* LEFT *
* ************/
// Make GP On Bottom
gp.AddEllipse(leftPlane);
// Get Bottom color
brush.Color = GetSideColor(fillColor, WallSide.Left);
// Fill Bottom Plane
g.FillPath(brush, gp);
// Shadow of the Body
FillCylinderShadow(g, front, gp, false);
// Check Draw Border
if (outLine)
g.DrawPath(borderPen, gp);
gp.Reset();
gp.AddArc(rightPlane, 270, 180);
gp.AddArc(leftPlane, 90, -180);
gp.CloseFigure();
/***************
* Body *
* ************/
// Color For Body is real Fill Color.
brush.Color = fillColor;
// Fill Body
g.FillPath(brush, gp);
// Shadow of the Body
FillCylinderShadow(g, front, gp, true);
// Check Draw Border
if (outLine)
g.DrawPath(borderPen, gp);
/***************
* RIGHT *
* ************/
gp.Reset();
gp.AddEllipse(rightPlane);
// Get Bottom color
brush.Color = GetSideColor(fillColor, WallSide.Back);
// Fill Top Plane
g.FillPath(brush, gp);
// Shadow of the Body
FillCylinderShadow(g, front, gp, true);
//Check Draw Border
if (outLine)
g.DrawPath(borderPen, gp);
// Dispose
gp.Dispose();
brush.Dispose();
borderPen.Dispose();
}
public static void FillWater(Graphics g, RectangleF front, SizeF depth, Color fillColor, Color borderColor, bool outLine)
{
if (front.Width <= 0 || front.Height <= 0)
return;
// Make Back Side Area
RectangleF aback = front;
// Make Depth
aback.X += depth.Width;
aback.Y -= depth.Height;
// Create Top and Bottom Plane.
RectangleF leftPlane;
RectangleF rightPlane;
// Create Graphics Object
GraphicsPath gp = new GraphicsPath();
rightPlane = new RectangleF(front.Width, front.Y, front.X, front.Height);
leftPlane = new RectangleF(front.X, front.Y, front.X, front.Height);
// Brush
SolidBrush brush = new SolidBrush(fillColor);
// Border Pen
Pen borderPen = new Pen(borderColor);
/***************
* LEFT *
* ************/
// Make GP On Bottom
gp.AddEllipse(leftPlane);
// Get Bottom color
brush.Color = GetSideColor(fillColor, WallSide.Left);
// Fill Bottom Plane
g.FillPath(brush, gp);
// Shadow of the Body
FillCylinderShadow(g, front, gp, false);
// Check Draw Border
if (outLine)
g.DrawPath(borderPen, gp);
gp.Reset();
gp.AddArc(rightPlane, 270, 180);
gp.AddArc(leftPlane, 90, -180);
gp.CloseFigure();
/***************
* Body *
* ************/
// Color For Body is real Fill Color.
brush.Color = fillColor;
// Fill Body
g.FillPath(brush, gp);
// Shadow of the Body
FillCylinderShadow(g, front, gp, true);
// Check Draw Border
if (outLine)
g.DrawPath(borderPen, gp);
/***************
* RIGHT *
* ************/
gp.Reset();
gp.AddEllipse(rightPlane);
// Get Bottom color
brush.Color = GetSideColor(fillColor, WallSide.Back);
// Fill Top Plane
g.FillPath(brush, gp);
// Shadow of the Body
FillCylinderShadow(g, front, gp, true);
//Check Draw Border
if (outLine)
g.DrawPath(borderPen, gp);
// Dispose
gp.Dispose();
brush.Dispose();
borderPen.Dispose();
}
あなたは常に簡単な方法を取ると、あなたのシリンダー90度回転し、そのように埋めることができます。 – Robaticus