C# 模拟带屏幕设备并将其调暗的最佳方法

发布于 2024-12-11 09:31:30 字数 239 浏览 0 评论 0原文

我已经在这个问题上摸索了几个月了,但我仍然不确定我能做些什么来实现想要的目标。

我需要构建一个真实的设备,即存在于现实世界中并且上面有屏幕的设备。到目前为止,我已经通过几种不同的方式完成了它,例如使用面板来模拟布局等。现在我正在使用代码构建每个控件。

问题是,有没有更好的方法来绘制这个屏幕? 如何使其变暗、变暗或变清晰? 处理完面板后,我总是在面板后面看到透明的背景。有什么办法可以消除这种重影效应吗?

提前致谢!

I've been messing around with this for a couple of months and I'm still not certain of what I can do to accomplish want a want.

I need to build a real device, that is, that exists in the real world and has a screen on it. So far, I have done it in a few different ways, like, using panels to simulate lays, etc. Now I'm currently building each control using code.

The thing is, is there any better way to draw this screen?
How can I dim it, make it darker or clearer?
I keep getting a transparent background behind the panels after I dispose them. Is there any way to remove this ghosting effect?

Thanks in advance!

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

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

发布评论

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

评论(3

星軌x 2024-12-18 09:31:30

基本上,您想要一个位于表单顶部的覆盖层。

开源项目 ObjectListView 实现了类似的覆盖。我破解了一点,它起作用了。
您可以在以下位置下载解决方案:
https://github.com/hamxiaoz/Misc/tree/master/DimScreen

构建解决方案并拖动轨迹栏,您可以看到表单变暗。您可以点击覆盖层。我想这就是你想要的。

Basically you want a overlay that's on top of your form.

The open source project ObjectListView implements a similar overlay. I hacked a little bit and it works.
You can download the solution at:
https://github.com/hamxiaoz/Misc/tree/master/DimScreen

Build the solution and drag the trackbar you can see the form is dimmed. And you can click through the overlay. I think that's what you want.

山色无中 2024-12-18 09:31:30

侵入性最小的方法可能是黑色或灰色的半透明覆盖层。只需根据需要不断调整透明度,直到它看起来像您想要的那样。

我不知道这是否有效,但它至少应该说明该技术:

using System;
using System.Drawing;
using System.Windows.Forms;

static class Utils {
    public static Form Plexiglass(Form tocover) {
        var frm = new Form();
        frm.BackColor = Color.DarkGray;
        frm.Opacity = 0.30;
        frm.FormBorderStyle = FormBorderStyle.None;
        frm.ControlBox = false;
        frm.ShowInTaskbar = false;
        frm.StartPosition = FormStartPosition.Manual;
        frm.AutoScaleMode = AutoScaleMode.None;
        frm.Location = tocover.Location;
        frm.Size = tocover.Size;
        frm.Show(tocover);
        return frm;
    }
}

The least invasive way would probably be a black or grey semi-transparent overlay. Just keep adjusting the transparency as needed until it looks the way you want it to.

I don't know if this works or not, but it should at least illustrate the technique:

using System;
using System.Drawing;
using System.Windows.Forms;

static class Utils {
    public static Form Plexiglass(Form tocover) {
        var frm = new Form();
        frm.BackColor = Color.DarkGray;
        frm.Opacity = 0.30;
        frm.FormBorderStyle = FormBorderStyle.None;
        frm.ControlBox = false;
        frm.ShowInTaskbar = false;
        frm.StartPosition = FormStartPosition.Manual;
        frm.AutoScaleMode = AutoScaleMode.None;
        frm.Location = tocover.Location;
        frm.Size = tocover.Size;
        frm.Show(tocover);
        return frm;
    }
}
陈年往事 2024-12-18 09:31:30

我添加了一些东西以使其更加高效。这是我的代码。

using System;
using System.Drawing;
using System.Windows.Forms;

static class Utils
{
    static Form ChildForm;
    public static Form OpenMask(Form tocover)
    {
        Form frm = new Form();
        ChildForm = frm;
        tocover.SizeChanged += AdjustPosition;
        tocover.Move += AdjustPosition;

        //frm.Move += AdjustPosition;
        //frm.SizeChanged += AdjustPosition;
        frm.BackColor = Color.Black;
        frm.Opacity = 0.50;
        frm.FormBorderStyle = FormBorderStyle.None;
        frm.ControlBox = false;
        frm.ShowInTaskbar = false;
        frm.StartPosition = FormStartPosition.Manual;
        frm.AutoScaleMode = AutoScaleMode.None;
        //frm.Location = tocover.Location;
        frm.Location = tocover.PointToScreen(System.Drawing.Point.Empty);
        frm.Size = tocover.ClientSize;
        frm.Show(tocover);
        return frm;
    }

    public static void CloseMask()
    {
        if (ChildForm != null)
        {
            ChildForm.Close();
            ChildForm.Dispose();
        }
    }

    private static void AdjustPosition(object sender, EventArgs e)
    {
        Form parent = sender as Form;
        if (ChildForm != null)
        {
            ChildForm.Location = parent.PointToScreen(System.Drawing.Point.Empty);
            ChildForm.ClientSize = parent.ClientSize;
        }
    }
}

I've added something to make it more productive. Here is my code.

using System;
using System.Drawing;
using System.Windows.Forms;

static class Utils
{
    static Form ChildForm;
    public static Form OpenMask(Form tocover)
    {
        Form frm = new Form();
        ChildForm = frm;
        tocover.SizeChanged += AdjustPosition;
        tocover.Move += AdjustPosition;

        //frm.Move += AdjustPosition;
        //frm.SizeChanged += AdjustPosition;
        frm.BackColor = Color.Black;
        frm.Opacity = 0.50;
        frm.FormBorderStyle = FormBorderStyle.None;
        frm.ControlBox = false;
        frm.ShowInTaskbar = false;
        frm.StartPosition = FormStartPosition.Manual;
        frm.AutoScaleMode = AutoScaleMode.None;
        //frm.Location = tocover.Location;
        frm.Location = tocover.PointToScreen(System.Drawing.Point.Empty);
        frm.Size = tocover.ClientSize;
        frm.Show(tocover);
        return frm;
    }

    public static void CloseMask()
    {
        if (ChildForm != null)
        {
            ChildForm.Close();
            ChildForm.Dispose();
        }
    }

    private static void AdjustPosition(object sender, EventArgs e)
    {
        Form parent = sender as Form;
        if (ChildForm != null)
        {
            ChildForm.Location = parent.PointToScreen(System.Drawing.Point.Empty);
            ChildForm.ClientSize = parent.ClientSize;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文