如何在不透明度为0.3的windows窗体上绘制零不透明度橡皮筋?
(橡皮筋是在Microsoft示例之后制作的
更新
我需要那个橡皮筋来做面具之类的工作。如果您使用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);
}
}