gpt4 book ai didi

c# - Winforms 应用程序中的填充橡皮筋

转载 作者:太空狗 更新时间:2023-10-29 21:20:33 24 4
gpt4 key购买 nike

如何在不透明度为 0.3 的窗体上绘制零不透明度橡皮筋?(橡皮筋是根据一个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);
}
}

关于c# - Winforms 应用程序中的填充橡皮筋,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2065162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com