2010-12-16 82 views
1

我一直在尋找很多東西,看過幾個例子,但他們至少對我沒有任何作用。這就是我需要的:在我的應用程序中,我需要爲工具欄使用透明的PNG圖標,並且還需要可拖動的可視對象表示,即72x72「頁面」圖標,可以拖動並可能覆蓋客戶區域中的所有元素。對於第一個我正在考慮使用按鈕,將其BackImage設置爲透明PNG並將BackColor設置爲「透明」:它不起作用,該按鈕始終顯示純色。至於面板,同樣的問題:我可以把一個透明的PNG作爲背景圖片,但是在PNG具有透明區域的地方,控件從不看起來「透明」。我認爲與一個圖片框和其他任何允許圖像背景的控件一樣。所以我想,這實際上是關於使控件的背景透明......任何想法?C#透明PNG按鈕,面板...怎麼樣?

我不在乎我是否需要創建某種自定義的「圖像按鈕」或「圖像面板」 - 無論如何 - 真正具有PNG透明按鈕,面板等!此外,請注意,它是關於PNG透明度,使用alpha通道,而不是透明像素,在這個年齡段,它吸引了恕我直言的GUI。

乾杯

litium

+0

plz add輸出圖像? – 2010-12-17 06:03:23

回答

1

好吧,我發現下面的代碼蒙山不僅對面板也爲按鈕,我想其他控件--except PictureBox的作品:

public class TransparentPanel : Panel <==change to Button for instance, and works 
    { 
     Timer Wriggler = new Timer(); 
     public TransparentPanel() 
     { 
      Wriggler.Tick += new EventHandler(TickHandler); 
      this.Wriggler.Interval = 500; 
      this.Wriggler.Enabled = true; 
     } 
     protected void TickHandler(object sender, EventArgs e) 
     { 
      this.InvalidateEx(); 
     } 
     protected override CreateParams CreateParams 
     { 
      get 
      { 
       CreateParams cp = base.CreateParams; 
       cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT 
       return cp; 
      } 
     } 
     protected void InvalidateEx() 
     { 
      if (Parent == null) 
      { 
       return; 
      } 
      Rectangle rc = new Rectangle(this.Location, this.Size); 
      Parent.Invalidate(rc, true); 
     } 
     protected override void OnPaintBackground(PaintEventArgs pevent) 
     { 
      // Do not allow the background to be painted 
     } 
    } 

對我的作品100%!似乎不適用於PictureBoxes。