2013-11-02 89 views

回答

2

透明度Windows Forms尚未實現正如人們所期望。具有透明背景實際上意味着控件使用其父項的背景。這意味着你需要讓你的覆蓋控制原始圖片框的子:

PictureBox overlay = new PictureBox(); 

overlay.Dock = DockStyle.Fill; 
overlay.BackColor = Color.FromArgb(128, Color.Blue); 

pictureBox2.Controls.Add(overlay); 

如果你想覆蓋圖片框包含你需要真正改變圖像的透明圖像:

PictureBox overlay = new PictureBox(); 
overlay.Dock = DockStyle.Fill; 
overlay.BackColor = Color.Transparent; 

Bitmap transparentImage = new Bitmap(overlayImage.Width, overlayImage.Height); 
using (Graphics graphics = Graphics.FromImage(transparentImage)) 
{ 
    ColorMatrix matrix = new ColorMatrix(); 
    matrix.Matrix33 = 0.5f; 

    ImageAttributes attributes = new ImageAttributes(); 
    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); 

    graphics.DrawImage(overlayImage, new Rectangle(0, 0, transparentImage.Width, transparentImage.Height), 0, 0, overlayImage.Width, overlayImage.Height, GraphicsUnit.Pixel, attributes); 
} 

overlay.Image = transparentImage; 

pictureBox2.Controls.Add(overlay); 
+0

非常感謝你,我正在尋找= D – user2948720