如题,具体来说就像这样:private void Form1_Paint(object sender, PaintEventArgs e)
{
   this.TransparencyKey = BackColor;                //使得整个窗口客户区是透明的   Bitmap bitMap = new Bitmap(@".\image\Test.png"); //Test.png是个透明度不一致的图片文件,它有全透明的部分,也有半透明的部分,也有完全不透明的
                                                           //部分   e.Graphics.DrawImage(bitMap, 0, 0);              //当我把bitmap画到设备对象e.Graphics上的时候,Test.png图片完全透明的地方,窗体还是透明
                                                           //的,Test.png不透明的部分窗体也不透明了,但Test.png半透明的部分窗体却不透明了,我要解决的
                                                           //就是使得Test.png的半透明部分,窗体的透明度和图片一致。
}                                                          //目前看来DrawImage这个函数估计是无法实现的了,因为它对Alpha通道貌似不支持这是我用到的Test.png图片(如果您还没理解到我意图的话,你可以把这个图片下载下来,然后把上述代码加到Paint事件试试,就明白了。.NET 2.0中里有没有这样的类?可以帮助我实现我的要求?(就是窗体的透明度也和图片一样保持原有的透明渐变效果)

解决方案 »

  1.   

    如果只用.net类库貌似是不行.要么全部透明度相等要么就不透明吧应该, 
      

  2.   

    你是想实现透明?
     用一个TIMER控件
     控制窗体的Opacity属性.
     最大到1.
    this.Opacity += 0.1;
      

  3.   


    using System;
    using System.Drawing;
    using System.Windows.Forms;class Demo : Form
    {
      protected override void OnPaint(PaintEventArgs e)
      {
        TransparencyKey = BackColor;
        Bitmap bitMap = new Bitmap("Test.png");
        e.Graphics.DrawImage(bitMap, -250, 210);
        base.OnPaint(e);
      }    [STAThread]
      static void Main()
      {
        Application.Run(new Demo());
      }
    }
      

  4.   

    不知这个有用没有:
    public void DrawImage(
    Image image,
    Point[] destPoints,
    Rectangle srcRect,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr
    )
      

  5.   

    我发现,Windows Vista 下,窗口的标题栏倒是半透明的。
      

  6.   


    那有没有API可以帮助实现的?
      

  7.   

    对对对,你说中要害了~~~
    我一直不知道怎么描述这个问题。
    在DrawImage的时候,它就是简单的画了上去,根本没有考虑到Alpha值得问题我就是在想用什么方法使得窗体的“局部Opacity值”,和图片的Alpha值相对应(貌似窗体的透明度是由Opacity决定的,但是Opacity值影响的是整个窗体的透明度)。
      

  8.   

    用PNG就行了
    然后把窗体设置透明``
    PNG背景透明就可以了
      

  9.   

    bitMap .MakeXXXXXXX(BackColor);//名字记不到了。。很长
    把bitmap透明色显示更改
      

  10.   


    那个
    我不是要Bitmap透明,我是要窗体的透明度和Bitmap中的Alpha值一致
      

  11.   

    背景图片的PNG背景不能是有颜色的
    必须是透明的```
      

  12.   

    好像是不行
    我试了这里的代码,办透明的地方还是切刀一样
    http://episteme.arstechnica.com/eve/forums/a/tpc/f/6330927813/m/432006814631
    [C#] PNG transparency over Transparent forms?
    Heh, After 4 hours of trying everything a newbie C# guy could think of, I'm begging for some help:Have a form, using either an image/color + transparency key, I have a transparent form. Fine.However, I have these nice little png images, I want to place on that form as buttons, and maybe even place over the buttons to convey information.Only problem is, that where the png alpha (like in the edges of the drop-shadow) overlaps the form, I get a weird mix of the drop-shadow, and the transparency key.I've used a variety of means to try to get past this. Nothing seems to work. So I'm beginning to think I'm going about this the wrong way. Any suggestions?[pointless speculation begins here] 
    The app is a "sits on your desktop and pretends to be a part of the wallpaper" style. The only idea I have is to somehow capture the appearance of the desktop window behind the control, and paint the form with this. This is pure speculation on my part, as I have no knowledge of whether this is a good idea or bad -- much less if it's even possible.Any experts out there wanna give the clueless a clue?
      

  13.   

    把图片放在Image控件中,当窗体透明时就自动透明了
      

  14.   

    你的问题"怎样实现窗体透明度和图片的透明度一致"是不明确的, 比如在80%透明的度下不同的颜色值有不同的透明表现,WPF与Windows Form有很大差异.
      

  15.   

    我不觉得这功能可以通过简单的调解透明度来解决.
    要不可以这样,拖动/resize时,你都对桌面截图(部分桌面会被该窗口遮住,所以可以考虑在完成拖动/完成resize时,隐藏窗口并截图),然后把截到的桌面和该窗体重叠部分画到桌面上,然后再画上你的图......
      

  16.   


    不对~~~”在DrawImage的时候,它就是简单的画了上去“,既然是画上去的。就是有有颜色组成的。肯定也包括透明的因素的。我觉得问题出在你的图片上。你的图片到了半透明的部分就已经不是透明的了。所以画在窗体上也是不透明的了。。应该是你的图片问题!!!
      

  17.   

    另一篇文章
    C#透明窗体(png图片渐变)源码
    http://blog.csdn.net/qim/archive/2007/08/08/1730973.aspx和非图片简单渐变
    C#打造仿真vista侧边栏(实现窗口透明,和透明渐变)基于XP系统
    http://blog.csdn.net/a137188467/archive/2008/05/27/2488459.aspx