Ich erstellen Speicher (Bild A) mit DrawStorage(). Um den Speicher zu füllen benutze ich FillWater(). Ich wollte Speicher mit Wasser entsprechend dem Level von 0-100% (leer-voll) wie Bild C füllen, aber die aktuelle Ausgabe wird von FillWater() wie das Bild B erzeugt. Wie man den Speicher füllt, um wie das Bild auszusehen C? Die Schwierigkeit besteht darin, den Speicher so zu füllen, dass er wie 3D aussieht (Bild C)Wie zeichne untere Hälfte einer 3D-Röhre mit C#
Sorry, wenn mein Englisch nicht gut ist. Ich hoffe auf Hilfe von Ihnen, die Experten sind, Danke.
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();
}
Man kann immer den einfachen Weg nehmen und einen Zylinder 90 Grad drehen und es auf diese Weise füllen. – Robaticus