wpf 相当于 Windows 窗体中的画布

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18117986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:23:19  来源:igfitidea点击:

Equivalent of canvas in Windows forms

c#wpfwinformscanvaspanel

提问by Uthistran Selvaraj.

I am creating a simple app to display multiple images one below the other. In WPF, I used Number of canvas equivalent to number of images and added those canvas to the main canvas. And using Imagecontrol in each canvas, i uploaded the images with me and it is looking good.

我正在创建一个简单的应用程序来显示多个图像,一个在另一个之下。在 WPF 中,我使用了与图像数量相当的画布数量,并将这些画布添加到主画布中。并在每个画布中使用图像控件,我上传了图像,看起来不错。

Now, I Am trying to do the same in Windows forms. I tried Panel (as the main canvas in WPF) and draw images over it by using Panel_Paint event. it is fine. But I need to add something(as I added multiple canvas in WPF), but did not get strike any thing. I planned for few panels, but all them need Panel_Paint to draw images over it.That is some what difficult to maintain... any other ideas?

现在,我试图在 Windows 表单中做同样的事情。我尝试了 Panel(作为 WPF 中的主画布)并使用 Panel_Paint 事件在其上绘制图像。没事。但是我需要添加一些东西(因为我在 WPF 中添加了多个画布),但没有得到任何东西。我计划了几个面板,但它们都需要 Panel_Paint 在上面绘制图像。这是一些难以维护的东西......还有其他想法吗?

回答by Vidas Vasiliauskas

You can create your own custom control and override OnPaint method. There you will be able to draw whatever you like in Canvas like mode. Create element specify its coordinates, draw it with Graphics object. And for overlaying use linear drawing order, items drawn later will be top most.

您可以创建自己的自定义控件并覆盖 OnPaint 方法。在那里,您将能够在类似 Canvas 的模式中绘制您喜欢的任何内容。创建元素指定其坐标,使用 Graphics 对象绘制它。对于叠加使用线性绘制顺序,后面绘制的项目将是最上面的。

回答by Gark Garcia

If you want to create a Paint-likecanvas, where you can draw simple graphics and images, you could use an instance of Graphics, like the following:

如果要创建类似Paint 的画布,可以在其中绘制简单的图形和图像,可以使用 的实例Graphics,如下所示:

// myPictureBox is the control where your graphics will be drawn
Graphics myCanvas = myPictureBox.CreateGraphics();

If you want to display a group of images, like .jpgare displayed in the files explorer, you could use a ListView.

如果要显示一组图像,例如.jpg在文件资源管理器中显示的图像,可以使用ListView.