在Winforms应用程序中填充橡皮筋

如何在不透明度为0.3的窗体上绘制零不透明橡皮筋? (橡皮筋是在微软的例子之后制作的


更新:

我需要那个橡皮筋来做像面具一样的东西。 如果您使用Jing或任何其他屏幕截图工具,您将在尝试制作屏幕截图时完全看到我需要做的事情:屏幕变为半透明,当您进行选择时,您将看到0不透明度选择

这是你要找的机器人吗?

  public Form1() { InitializeComponent(); DoubleBuffered = true; } bool mouseDown = false; Point mouseDownPoint = Point.Empty; Point mousePoint = Point.Empty; protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); mouseDown = true; mousePoint = mouseDownPoint = e.Location; } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); mouseDown = false; } protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); mousePoint = e.Location; Invalidate(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (mouseDown) { Region r = new Region(this.ClientRectangle); Rectangle window = new Rectangle( Math.Min(mouseDownPoint.X, mousePoint.X), Math.Min(mouseDownPoint.Y, mousePoint.Y), Math.Abs(mouseDownPoint.X - mousePoint.X), Math.Abs(mouseDownPoint.Y - mousePoint.Y)); r.Xor(window); e.Graphics.FillRegion(Brushes.Red, r); Console.WriteLine("Painted: " + window); } } 

绘图时需要使用部分不透明的颜色:

MyDrawReversibleRectangle方法中更新了链接文章的MyDrawReversibleRectangle

 ControlPaint.DrawReversibleFrame( rc, Color.FromArgb(80, 120, 120, 120), FrameStyle.Dashed ); 

我使用了@Dearmash在我的开源应用程序BugTracker.NET附带的屏幕捕获实用程序中提供的代码。 该应用程序不是很大,所以如果你正在做屏幕捕获的东西,它可能是一个很好的起点。 更多信息:

http://ifdefined.com/blog/post/Screen-capture-utility-in-C-NET.aspx

只需使用其他表单,而不在任务栏或其他表单选项中显示。 设置仅显示橡皮筋的表单区域。 并确保两个窗口的行为就像是一个窗口(移动,关闭,……)。 我知道这不是一种优雅的方式,但通过一点点工作,它可以产生良好的效果。 您可以确保表单位于表单层次结构的顶部,但仍然无法获得焦点。

通过设置区域良好,所有事件将转到另一种forms。

这就是我解决同等问题的方式(我不是说这是一个很好的解决方案,但它有效)