2013-11-02 117 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