我想繪制/制作一個三角形圖形,該圖形將在我運行程式后立即出現,但我無法找出正確的命令。這是我用來制作矩形物件的命令。
private void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Aquamarine, _x, _y, 100, 100);
}

所以當我制作物體時,我會讓它自動移動。
我搜索了教程,但找不到任何合適的。請幫忙。
uj5u.com熱心網友回復:
您可以使用FillPolygon并指定 3 個三角形點。
e.Graphics.FillPolygon(Brushes.Aquamarine, new Point[] { new Point(150, 100), new Point(100, 200), new Point(200, 200) });
或者你可以創建一個FillTriangle擴展方法
public static class Extensions
{
public static void FillTriangle(this Graphics g, PaintEventArgs e, Point p, int size)
{
e.Graphics.FillPolygon(Brushes.Aquamarine, new Point[] { p, new Point(p.X - size, p.Y (int)(size * Math.Sqrt(3))), new Point(p.X size, p.Y (int)(size * Math.Sqrt(3))) });
}
}
像這樣打電話
e.Graphics.FillTriangle(e, new Point(150, 100), 500);
對于直角三角形使用這個
e.Graphics.FillPolygon(Brushes.Aquamarine, new Point[] { p, new Point(p.X, p.Y size * 2), new Point(p.X size, p.Y size * 2) });
為了鈍這個
e.Graphics.FillPolygon(Brushes.Aquamarine, new Point[] { p, new Point(p.X - size, p.Y height), new Point(p.X size, p.Y height) });
此代碼將輸出此
e.Graphics.FillRightTriangle(e, new Point(50, 20), 100);
e.Graphics.FillTriangle(e, new Point(400, 20), 70);
e.Graphics.FillObtuseTriangle(e, new Point(230, 200), 50, 130);

uj5u.com熱心網友回復:
有DrawPolygon可能做你想要的,你只需要指定三角形的三個頂點。
https://docs.microsoft.com/en-us/dotnet/api/system.drawing.graphics.drawpolygon?view=dotnet-plat-ext-6.0
編輯:FillPolygon可能更符合您的需要,抱歉。
https://docs.microsoft.com/en-us/dotnet/api/system.drawing.graphics.fillpolygon?view=dotnet-plat-ext-6.0
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/448778.html
