简体   繁体   English

C#是否具有Pascal画布之类的东西?

[英]Does C# have something like a Pascal canvas?

In Pascal it is pretty easy to draw lines and realise something like turtle graphics because you can draw right on the form. 在Pascal中,绘制线条和实现类似龟图形的操作非常容易,因为您可以在表单上直接绘制。 After trying to find something related in C# fon r quite a while now I did not come across anything useful. 尝试查找C#格式中的相关内容已有一段时间之后,现在我没有发现任何有用的信息。 My questions are: 我的问题是:

  • Is there any way in C# to manage this task as it is in Pascal? 和Pascal一样,C#中有什么方法可以管理此任务?
  • If not what "standard" other solutions can I use to implement such a turtle? 如果不是,我可以使用什么“标准”其他解决方案来实现这种乌龟?

Override the OnPaint on your form and then you can use the graphics object off of the PaintEventArgs to draw on the form: 覆盖窗体上的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));
}

Which yields a form that looks like this: 产生如下形式的表格:

样品

If you are using WinForms, take a look at this example on MSDN which shows how to draw straight on to a form using System.Drawing.Graphics 如果您使用的是WinForms,请查看MSDN上的此示例,该示例显示如何使用System.Drawing.Graphics直接绘制到窗体上

How to: Draw a Filled Rectangle on a Windows Form 如何:在Windows窗体上绘制实心矩形

This code sample is straight from that link: 该代码示例直接来自该链接:

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM