C#填充多边形(三角形)

标签 c# winforms drawing draw

我在绘制两个多边形时遇到问题。 我想填充两个三角形,但一个大于第二个。 我在 winforms 中使用 UserControl。 代码:

Point[] DOWN = new Point[] {new Point(0, 0), new Point(10, 0), new Point(5, 5)};
Point[] UP = new Point[] { new Point(0, 15), new Point(10, 15), new Point(5, 10) };

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            SolidBrush brush = new SolidBrush(Color.FromArgb(253, 198, 19));       
            e.Graphics.FillPolygon(brush, DOWN);
            e.Graphics.FillPolygon(brush, UP);
            brush.Dispose();
        }

This is result of fill polygons 问题出在哪里?

最佳答案

尝试设置 PixelOffsetMode 属性:

e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
using (SolidBrush brush = new SolidBrush(Color.FromArgb(253, 198, 19))) {
  e.Graphics.FillPolygon(brush, DOWN);
  e.Graphics.FillPolygon(brush, UP);
}

结果:

enter image description here

关于C#填充多边形(三角形),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21684873/

相关文章:

c# - 负前瞻行为不符合预期

c# - 无法将用户控件放在窗体上

c# - 将多个文本框条目保存到单个文件,C#

react-native - 如何在 React Native 中制作交互式绘图应用程序?

c# - [Serializable] 属性有哪些 ISerializable 没有的功能?

c# - 在图表系列中累积值 - WPF DevExpress

c# - Word Interop Delete 导致参数错误

C# winforms webbrowser控件,上下键滚动

cocoa - 用 Cocoa 绘制线和点

c# - 如何绘制图像?