Я создаю хранилище (Рисунок A) с DrawStorage ().Для заполнения хранилища я использую FillWater ().Я хотел заполнить хранилище водой в соответствии с уровнем 0-100% (пустой-заполненный), таким как рисунок C, но текущий вывод генерируется из FillWater (), как рисунок B. Как заполнить хранилище, чтобы оно выглядело как рисунокС?Сложность заключается в том, как заполнить хранилище так, чтобы оно выглядело как 3D (Рисунок C)
Извините, если мой английский не очень хорош.Я надеюсь, что помощь тех, кто является экспертами, спасибо.

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();
}