C#有像Pascal画布一样的东西吗?

时间:2014-07-18 12:40:49

标签: c# drawing

在Pascal中,绘制线条并实现像turtle graphics之类的东西非常容易,因为你可以直接在表格上绘制。在尝试在C#fon r中找到相关的东西之后,我现在没有遇到任何有用的东西。我的问题是:

  • 在C#中是否有任何方法来管理Pascal中的任务?
  • 如果没有,我可以使用哪种“标准”其他解决方案来实施这样的海龟?

2 个答案:

答案 0 :(得分:2)

覆盖表单上的OnPaint,然后您可以使用PaintEventArgs之外的图形对象在表单上绘图:

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    e.Graphics.DrawRectangle(Pens.Red, new Rectangle(0,0,20,20));
    e.Graphics.DrawLine(Pens.Blue, 20,20,30,30);
    e.Graphics.DrawIcon(this.Icon, new Rectangle(30,30,30,30));
}

这会产生如下形式:

Sample

答案 1 :(得分:0)

如果您使用的是WinForms,请查看MSDN上的此示例,其中显示了如何使用System.Drawing.Graphics直接绘制到表单

How to: Draw a Filled Rectangle on a Windows Form

此代码示例直接来自该链接:

System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(myBrush, new Rectangle(0, 0, 200, 300));
myBrush.Dispose();
formGraphics.Dispose();
相关问题