读书人

为啥无法透明啊

发布时间: 2013-03-27 11:22:42 作者: rapoo

为何无法透明啊?
如题,为什么啊button不是透明的?
public Form1()
{
InitializeComponent();
UseTransparentProperty();
}

private void UseTransparentProperty()
{

// Set up the PictureBox to display the entire image, and
// to cover the entire client area.
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Dock = DockStyle.Fill;

try
{
// Set the Image property of the PictureBox to an image retrieved
// from the file system.
pictureBox1.Image =
Image.FromFile("C:\\Documents and Settings\\All Users\\" +
"Documents\\My Pictures\\示例图片\\sunset.jpg");

// Set the Parent property of Button1 and Button2 to the
// PictureBox.
button1.Parent = pictureBox1;
button2.Parent = pictureBox1;

// Set the Color property of both buttons to transparent.
// With this setting the buttons assume the color of their
// parent.
button1.BackColor = Color.Transparent;
button2.BackColor = Color.Transparent;

}
catch (System.IO.FileNotFoundException)
{
MessageBox.Show("There was an error." +


"Make sure the image file path is valid.");
} 控件透明
[解决办法]

button1.FlatStyle = FlatStyle.Flat;

加上这一句就行了。。。

读书人网 >C#

热点推荐