1
我有一些看起来很简单的代码,应该绘制一个椭圆,但似乎并没有出现。这里是我的代码:Windows窗体图形没有绘制
public partial class ThreeBodySim : Form
{
public ThreeBodySim()
{
InitializeComponent();
this.DoubleBuffered = true;
Graphics graphics = displayPanel.CreateGraphics(); // Separate panel to display graphics
Rectangle bbox1 = new Rectangle(30, 40, 50, 50);
graphics.DrawEllipse(new Pen(Color.AliceBlue), bbox1);
}
}
我是否缺少重要的东西?
使用Paint事件。您的CreateGraphics不能在构造函数中使用 - 表单不可见。 CreateGraphics也会忽略你的DoubleBuffer。 – LarsTech