我想实现一个效果一个Form 窗口 全屏 设置50透明度  里面放一个PictureBox 我想让这个PictureBox不透明 怎么做? 请注意上面的2个要求!使用窗口的Opacity属性设置,里面的个PictureBox 空件一样也会变透明的![所以排除这个方法]
后来我使用的 API的 SetLayeredWindowAttributes 函数来实现这个效果。
代码如下:
WinAPI.cs 
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;namespace WindowsFormsApplication10
{
    class WinAPI
    {
        [DllImport("user32.dll")]
        public extern static IntPtr GetDesktopWindow();        [DllImport("user32.dll")]
        public extern static bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
        public static uint LWA_COLORKEY = 0x00000001;
        public static uint LWA_ALPHA = 0x00000002;        [DllImport("user32.dll")]
        public extern static uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
        [DllImport("user32.dll")]
        public extern static uint GetWindowLong(IntPtr hwnd, int nIndex);        public enum WindowStyle : int
        {
            GWL_EXSTYLE = -20
        }        public enum ExWindowStyle : uint
        {
            WS_EX_LAYERED = 0x00080000
        }    }
}
Form1.cs 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void button1_Click(object sender, EventArgs e)
        {
          SetWindowTransparent(100);
        }
        private void SetWindowTransparent(byte bAlpha)
        {
            try
            {
                WinAPI.SetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE,
                    WinAPI.GetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE) | (uint)WinAPI.ExWindowStyle.WS_EX_LAYERED);                WinAPI.SetLayeredWindowAttributes(this.Handle, 0, bAlpha, WinAPI.LWA_COLORKEY | WinAPI.LWA_ALPHA);
            }
            catch
            {
            }
        }
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;                cp.Parent = WinAPI.GetDesktopWindow();
                cp.ExStyle = 0x00000080 | 0x00000008;//WS_EX_TOOLWINDOW | WS_EX_TOPMOST                return cp;
            }
        }
    }
}
但是发现出来的效果和直接设置Opacity属性效果一样!空件也跟着透明,代码是网上找的,可能哪个地方还需要修改才可以打到我的效果! 可是我没成功,请各位大狭帮忙啊!
另:我用另一种办法 设置窗口 ransparencyKey属性 来使整个窗口透明(具体办法看http://topic.csdn.net/u/20080714/14/9f9fa409-97a9-4d92-9de5-865f7a03baa5.html?seed=249527672 3楼。然后搞个 PNG半透明的背景 ! 发现全透效果能出来,可是半透就 不透了!不知道为什么!
我的另一个帖子http://topic.csdn.net/u/20080714/14/9f9fa409-97a9-4d92-9de5-865f7a03baa5.html?seed=249527672问的同样的问题,还未结,请哪位大狭帮忙 OK了! 2贴分数一起逢上,当然还可再加!