简体   繁体   English

在C#中,Java的canvas对象有什么用呢?

[英]What is the equivalent to Java's canvas object in C#?

I'm working on creating a basic application that will let a user draw (using a series of points) and I plan to do something with these points. 我正在创建一个基本的应用程序,让用户绘制(使用一系列点),我打算用这些点做点什么。

If this were Java, I think I would probably use a canvas object and some Java2D calls to draw what I want. 如果这是Java,我想我可能会使用canvas对象和一些Java2D调用来绘制我想要的东西。

All the tutorials I've read on C#/Drawing involve writing your own paint method and adding it to the paint event for the form. 我在C#/ Drawing上阅读的所有教程都涉及编写自己的绘制方法并将其添加到表单的绘图事件中。 However, I'm interested in having some traditional Form controls as well and I don't want to be drawing over them. 但是,我也有兴趣使用一些传统的Form控件,我不想画它们。 So, is there a "Canvas" object where I can constrain what I'm drawing on? 那么,是否有一个“画布”对象,我可以约束我正在绘制的东西?

Also, is WinForms a poor choice given this use case? 另外,考虑到这个用例,WinForms是一个糟糕的选择吗? Would WPF have more features that would help enable me to do what I want? WPF会有更多功能可以帮助我做我想做的事吗? Or Silverlight? 还是Silverlight?

A Bitmap will work fine, display it with the PictureBox.Image property. Bitmap可以正常工作,使用PictureBox.Image属性显示它。 Use Graphics.FromImage() to get the Graphics object you'll need to draw on the bitmap. 使用Graphics.FromImage()获取您需要在位图上绘制的Graphics对象。 Use PictureBox.Invalidate() to let the PB know that it needs to update the image on the screen. 使用PictureBox.Invalidate()让PB知道它需要更新屏幕上的图像。

Well, there is a control called 'canvas' in WPF which may suite you. 好吧,在WPF中有一个名为“canvas”的控件可能适合你。 If you are using Windows Forms, i think the best choice will be to draw on a panel control. 如果您使用的是Windows窗体,我认为最好的选择是绘制面板控件。 Windows forms are in no way a poor choice. Windows窗体绝不是一个糟糕的选择。 Indeed, when using them you can even develop a cross-platform applications. 实际上,在使用它们时,您甚至可以开发跨平台应用程序。 However, WPF is more 'rich' in some way. 但是,WPF在某种程度上更“富有”。 I think that if you are not aiming at any other platforms, and you don't have to stick with .NET 2.0 WPF is a preferred choice (especially, if you are going to use some graphics in your application, because WPF uses hardware acceleration). 我认为,如果你不是针对任何其他平台,并且你不必坚持使用.NET 2.0 WPF是一个首选(特别是,如果你要在你的应用程序中使用一些图形,因为WPF使用硬件加速)。

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

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