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

前端之家收集整理的这篇文章主要介绍了Winforms应用程序中的c#填充橡皮筋前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在不透明度为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#相关文章