Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# c语言中带分层窗口的启动屏幕#_C#_Splash Screen_Layered Windows - Fatal编程技术网

C# c语言中带分层窗口的启动屏幕#

C# c语言中带分层窗口的启动屏幕#,c#,splash-screen,layered-windows,C#,Splash Screen,Layered Windows,在多层窗口中,我可以通过点击工作,但在窗口中的背景图片后仍会看到一些灰色,如何删除?我看过堆栈溢出和codeproject,但找不到解决方案 这是我的代码: private Margins marg; internal struct Margins { public int Left, Right, Top, Bottom; } public enum GWL { ExStyle = -20 } pub

在多层窗口中,我可以通过点击工作,但在窗口中的背景图片后仍会看到一些灰色,如何删除?我看过堆栈溢出和codeproject,但找不到解决方案

这是我的代码:

private Margins marg;
    internal struct Margins 
    {
        public int Left, Right, Top, Bottom;
    }

    public enum GWL
    {
        ExStyle = -20
    }

    public enum WS_EX
    {
        Transparent = 0x20,
        Layered = 0x80000
    }

    public enum LWA
    {
        ColorKey = 0x1,
        Alpha = 0x2
    }

    const Int32 HTCAPTION = 0x02;
    const Int32 WM_NCHITTEST = 0x84;
    const byte AC_SRC_OVER = 0x00;
    const byte AC_SRC_ALPHA = 0x01;

    [DllImport("user32.dll", SetLastError = true)]

    private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]

    static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, LWA dwFlags);

    [DllImport("dwmapi.dll")]
    static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins);

    public Form1() {
        InitializeComponent();

        //BackColor = Color.Aqua;
        //TransparencyKey = Color.Aqua;

        StartPosition = FormStartPosition.CenterScreen;
        BackgroundImage = new Bitmap(mypicture);
        BackgroundImageLayout = ImageLayout.Stretch;
        this.Size = mypicture.Size;
        this.FormBorderStyle = FormBorderStyle.None;

        TopMost = true;
        Visible = true;

        int initialsytle = (int) GetWindowLong(this.Handle,-20);
        initialsytle = initialsytle |0x80000 | 0x20;
        IntPtr pointer = (IntPtr) initialsytle;
        SetWindowLong(this.Handle, -20, pointer);
        SetLayeredWindowAttributes(this.Handle, 0, 128, LWA.ColorKey);



    }

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

        marg.Left = 0;
        marg.Top = 0;
        marg.Right = this.Width;
        marg.Bottom = this.Height;

        DwmExtendFrameIntoClientArea(this.Handle, ref marg);

    }
}

您的透明键显示为黑色。当图像具有部分透明的像素时,将变为灰色。Photoshop通常用于形状的边缘,它很容易做到这一点。这些像素将颜色从黑色变为灰色。它不再与透明键匹配,因此您将看到它们。你需要一个更好的图像。如果我的照片中没有阴影,你也可以这样做