Jon*_*tin 3 c# graphics winforms
我有一些看起来很简单的代码,应该绘制一个椭圆,但它似乎没有出现。这是我的代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么重要的东西吗?
使用该Paint()事件在您的表单上绘图。我建议PictureBox在表单上使用 a ,因为它不会有太多的闪烁。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.DoubleBuffered=true;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
Rectangle bbox1=new Rectangle(30, 40, 50, 50);
e.Graphics.DrawEllipse(new Pen(Color.Purple), bbox1);
}
private void pictureBox1_Resize(object sender, EventArgs e)
{
pictureBox1.Invalidate();
}
}
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
4107 次 |
| 最近记录: |