C# picturebox 加载图片后透明显示在另一控件之上

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;
using System.Drawing.Imaging; namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} public static void ChangeOpacity(PictureBox pb, Single opacity, Control parent)
{
var img = pb.Image;
var bmp = new Bitmap(img.Width, img.Height);
using (var g = Graphics.FromImage(bmp))
{
var colorMatrix = new ColorMatrix();
colorMatrix.Matrix33 = opacity;
var attr = new ImageAttributes();
attr.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(img, new Rectangle(, , bmp.Width, bmp.Height), , , img.Width, img.Height, GraphicsUnit.Pixel, attr);
}
pb.BackColor = Color.Transparent;
pb.Image = bmp;
pb.Parent = parent;
pb.Left = ;
pb.Top = ;
} private void Form1_Load(object sender, EventArgs e)
{
ChangeOpacity(pictureBox1, 0.3F, button1);
}
}
}

C# picturebox 加载图片后透明显示在另一控件之上

这个方法只能保证picturebox仅对其父控件透明
 
上一篇:PHP AES的加密解密


下一篇:Fedora14下首次搭建Samba服务器遇到的一些问题