OnPaint()
現在、作成中のカスタム コントロールのメソッドをオーバーライドしようとしています。
オブジェクトは単純なパネルですが、次のように、別の種類の方法で表示しようとしています。
私は GraphicsPath を使用してこのタスクを完了しようとしていますが、現在は次のようになっているため、期待どおりに動作していません。
これは、図 1を再作成するために取り組んできたコードです。
private GraphicsPath GetFigurePath(RectangleF rect)
{
GraphicsPath path = new GraphicsPath();
Point TopLeft = new Point((int)rect.X, (int)rect.Y);
Point TopRight = new Point((int)rect.X + (int)rect.Width, (int)rect.Height);
Point BottomLeft = new Point((int)rect.X, (int)rect.Y + (int)rect.Height);
Point BottomRight = new Point((int)rect.X + (int)rect.Width, (int)rect.Y + (int)rect.Height);
Point MidPoint = new Point((TopLeft.X + BottomLeft.X) / 2, (TopLeft.Y + BottomLeft.Y) / 2);
Point Fulcrum = new Point((int)MidPoint.X + (int)rect.Width, MidPoint.Y);
path.StartFigure();
// The rectangle
path.AddLine(TopLeft, TopRight);
path.AddLine(TopRight, BottomRight);
path.AddLine(BottomRight, BottomLeft);
path.AddLine(BottomLeft, TopLeft);
// The pointy end
path.AddLine(TopRight, Fulcrum);
path.AddLine(Fulcrum, BottomRight);
path.CloseFigure();
return path;
}
protected override void OnPaint(PaintEventArgs e)
{
if (HasBorderStyle) {
base.OnPaint(e);
this.FlatStyle = FlatStyle.Flat;
this.Size = new Size(DEFAULT_WIDTH, DEFAULT_HEIGHT);
this.BackColor = Color.Silver;
this.ForeColor = Color.White;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
RectangleF rectSurface = new RectangleF(0, 0, this.DEFAULT_WIDTH, this.DEFAULT_HEIGHT);
RectangleF rectBorder = new RectangleF(1, 1, this.DEFAULT_WIDTH - 0.8f, this.DEFAULT_HEIGHT - 1);
using (GraphicsPath pathSurface = GetFigurePath(rectSurface))
using (GraphicsPath pathBorder = GetFigurePath(rectBorder))
using (Pen penSurface = new Pen(this.Parent.BackColor, 2))
using (Pen penBorder = new Pen(borderColour, borderSize)) {
penBorder.Alignment = PenAlignment.Inset;
this.Region = new Region(pathSurface);
e.Graphics.DrawPath(penSurface, pathSurface);
e.Graphics.DrawPath(penBorder, pathBorder);
}
}
}
私が欠けているものや間違っていることを誰かに教えてもらえますか?