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

发布于 2024-08-17 11:44:26 字数 303 浏览 9 评论 0原文

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


更新:

我需要橡皮筋来像遮罩一样工作,如果你使用 Jing 或任何其他屏幕截图工具,当你尝试制作屏幕截图时,你会确切地看到我需要做什么:屏幕会消失。半透明,当您进行选择时,您将看到不透明度为 0 的选择

how can i draw a zero opacity rubber band over a windows form with 0.3 opacity?
(The rubber band is made after a Microsoft example


Update:

I need that rubber band to work something like a mask. If you use Jing or any other screen shot tool, you will see EXACTLY what I need to do when do you try to make a screenshot: the screen goes semi-opaque and when you make the selection, you will see the 0 opacity selection

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

霊感 2024-08-24 11:44:27

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

通过设置好区域,所有事件都将转为另一种形式。

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

Just use an additional form, without showing it in the taskbar, or other Form-options. Set the region of the form that it only shows the rubber band. And make sure both windows behave as if it was one window (moving, closing,...). I know it's not an elegant way, but with a little work it can produce good results. You can make sure that the form is on top in the form-hierarchy and still doen't receive focus.

By setting the region good, all events will go to the other form.

That's the way I worked out an equivalent problem (I don't say it's a good solution, but it works)

孤者何惧 2024-08-24 11:44:26

这是您要找的机器人吗?

    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);
        }
    }

Is this the droid you were looking for?

    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);
        }
    }
花间憩 2024-08-24 11:44:26

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

MyDrawReversibleRectangle 方法中从链接文章更新了行:

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

You need to use a partially opaque color when drawing:

Updated line from linked article, in the MyDrawReversibleRectangle method:

ControlPaint.DrawReversibleFrame( rc, Color.FromArgb(80, 120, 120, 120), FrameStyle.Dashed );
感受沵的脚步 2024-08-24 11:44:26

我使用了 @Dearmash 在我的开源应用程序 BugTracker.NET 附带的屏幕捕获实用程序中提供的代码。该应用程序不是很大,因此如果您正在执行屏幕捕获操作,这可能是一个很好的起点。更多信息请参见:

http://ifdefine.com/博客/帖子/Screen-capture-utility-in-C-NET.aspx

I used the code that @Dearmash supplied in the screen capture utility that comes with my open source app BugTracker.NET. The app isn't very big, so if you are doing screen capture stuff, it might be a good starting point. More info here:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文