我使用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 2012-03-30 16:45:18