C# 如何制作可调整大小的矩形选择工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/716626/
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-08-04 22:18:55  来源:igfitidea点击:

How to make a resizeable rectangle selection tool?

c#user-interfaceqtqt4

提问by xpol

I'm trying to write a very simple photo editor using C# 2008 or QT4.

我正在尝试使用 C# 2008 或 QT4 编写一个非常简单的照片编辑器。

How to make a resizeable rectangle selection tool like the photoshop did?

如何像photoshop一样制作可调整大小的矩形选择工具?

回答by dommer

If you are talking about the "classic" "rubber band" type of selection rectangle, check out How to draw a rubber band rectangle or a focus rectangle in Visual C#.

如果您谈论的是“经典”“橡皮筋”类型的选择矩形,请查看如何在 Visual C# 中绘制橡皮筋矩形或焦点矩形

回答by Dave Swersky

I don't know the specific calls, but the idea is this:

我不知道具体的电话,但想法是这样的:

You want to draw a transparent rectangle with an opaque or dotted border. The rectangle appears when the mouse button is clicked. While the button is held, the dimension of the rectangle will change as the mouse moves, with the top-left point at the position where the button was clicked and the bottom-right following the mouse as it moves. Releasing the button causes the rectangle to fix its position over the selection area.

您想绘制一个带有不透明或虚线边框的透明矩形。单击鼠标按钮时会出现矩形。按住按钮时,矩形的尺寸会随着鼠标移动而变化,左上角位于单击按钮的位置,右下角随着鼠标移动而变化。释放按钮会使矩形在选择区域上固定其位置。

You should be able to figure out the particulars from a resource on the C# Drawingnamespace.

您应该能够从 C#Drawing命名空间上的资源中找出详细信息。

回答by kevindaub

WPF Code Example: http://www.codeproject.com/KB/WPF/wpfmarchingants.aspx?display=Print

WPF 代码示例:http: //www.codeproject.com/KB/WPF/wpfmarchingants.aspx?display =Print

This one is a bit more complicated because it involves image cropping, but if you scroll down to the selection rectangle, you can see the basic formulas for calculating the rectangle: http://69.10.233.10/KB/WPF/ImageCropper.aspx

这个稍微复杂一些,因为它涉及图像裁剪,但是如果向下滚动到选择矩形,您可以看到计算矩形的基本公式:http: //69.10.233.10/KB/WPF/ImageCropper.aspx

Lastly, another one using GDI: http://codelog.blogial.com/2008/10/31/rubber-band-selection-rectangle-in-c/

最后,另一个使用 GDI:http: //codelog.blogial.com/2008/10/31/rubber-band-selection-rectangle-in-c/

If you provide more specifics, I'm sure we can help you out more.

如果您提供更多细节,我相信我们可以为您提供更多帮助。