Windows 8.1中c#.net中的半透明面板 [英] semi transparent panel in c# .net on Windows 8.1

查看:74
本文介绍了Windows 8.1中c#.net中的半透明面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我有半透明面板用c#编写.net 4.0

在Windows XP,Vista,7上工作正常但它在Windows 8,8.1上运行不正常。

在Windows 8和8.1上,面板不是半透明的。

有没有人可以告诉我为什么?



这是我的代码



Hello

I have semi transparent panel written in c# for .net 4.0
it work fine on Windows XP,Vista,7 but it doesn't work fine on Windows 8, 8.1.
On Windows 8 and 8.1 the panel is not semitransparent.
Is there anyone who can tell me why?

Here is my code

public class MyPanel : System.Windows.Forms.Panel
{
    public MyPanel() : base()
    {
        this.SetStyle(ControlStyles.UserPaint, true);
        this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        this.SetStyle(ControlStyles.ResizeRedraw, true);
        this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
    }

    protected override CreateParams CreateParams
    {
        get
        {
            var cp = base.CreateParams;
            cp.ExStyle |= 0x00000020;
            return cp;
        }
    }

    protected override void OnPaintBackground(PaintEventArgs e)
    {
        // Do not paint background.
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        e.Graphics.Clear(System.Drawing.Color.White);
        e.Graphics.CopyFromScreen(this.PointToScreen(new Point(0, 0)), new Point(0, 0), new Size(this.Width, this.Height));
        e.Graphics.FillRectangle(new SolidBrush(System.Drawing.Color.FromArgb(120, System.Drawing.Color.Gray)), new Rectangle(new Point(0, 0), this.Size));
    }
}

推荐答案

Win 8中不存在透明度...



你可以使用这个实用程序在后台工作 [ ^ ]
Transparency doesn't exist in Win 8...

But you can use this utility to work in the background[^]


因为看来你好像正在使用WinForms,您可以使用 Opacity 表单成员来设置透明度。



我已经完成了半透明的东西,但基本上,我使用两种形式,只有一个部分是半透明的。然后我同步移动和激活,以便最终用户看起来像一个单独的表单里面有一个半透明区域。



不透明表单可能使用一个颜色键为完全透明的区域,其他形式的位置。第二种形式是没有边框创建的。



如果我记得很好,为了激活我需要访问API,因为我希望主窗体在激活时显示为激活用户点击半透明表格。
Since it seems that you are using WinForms, you could use Opacity member of the form to set transparency.

I have done semi-transparent stuff but essentially, I use two forms so that only one part is semi-transparent. I then synchronize moving and activation so to the end user it appears as a single form have a semi-transparent area inside it.

The opaque form probably uses a color key for fully transparent area where the other form is located. The second form is created without border.

If I remeber well, for the activation I need to access the API as I want the main form to appears as activate when the user click on the semi-transparent form.


这篇关于Windows 8.1中c#.net中的半透明面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆