简体   繁体   English

在Winforms中创建叠加控件

[英]Creating Overlay Control in winforms

I am using c# winforms to show an Image. 我正在使用c#winforms显示图像。 The displaying of the image is done using a user control. 图像的显示是使用用户控件完成的。 Now I want to provide the user to draw lines, put other small images, write text etc over the image on an overlay control. 现在,我想为用户提供画线,放置其他小图像,在覆盖控件上的图像上写文本等的功能。 How can I provide this functionality? 如何提供此功能? If I use another user control to show the overlay control with transparent back, will that work?? 如果我使用另一个用户控件来显示带有透明背面的叠加控件,那行得通吗? any other solution will be welcome. 任何其他解决方案都将受到欢迎。

You might try approaching this with a canvas ( Panel ) that handles painting the image as the background and all the annotations/markup afterwards. 您可以尝试使用画布( Panel )来处理此问题,该画布处理将图像绘制为背景,然后再绘制所有注释/标记。 This will make the foreground appear to be transparent. 这将使前景显得透明。 I expect you'll want to set Control.DoubleBuffer for performance. 我希望您可以设置Control.DoubleBuffer来提高性能。

You might experiment with setting the style ControlStyles .AllPaintingInWmPaint. 您可能会尝试设置样式ControlStyles .AllPaintingInWmPaint。 Also, try overriding Control.OnPaintBackground and do nothing, and override Control.OnPaint and do all your painting inside there. 另外,尝试覆盖Control.OnPaintBackground而不执行任何操作,并覆盖Control.OnPaint并在其中进行所有绘制。

If performance is still unacceptable, pay close attention to the PaintEventArgs.ClipRect property. 如果性能仍然不能令人满意,请密切注意PaintEventArgs.ClipRect属性。 This is the only area you need to paint. 这是您唯一需要绘制的区域。 The trick is figuring out which of your annotations/overlays intersect with this rectangle and painting them in the correct order. 诀窍是弄清楚您的哪些注释/叠加层与此矩形相交,并以正确的顺序绘制它们。

Either this canvas or a higher level control will need to track mouse movement so you know where to draw the lines, paste images, etc. 此画布或更高级别的控件都需要跟踪鼠标的移动,以便您知道在何处绘制线条,粘贴图像等。

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

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