所以我有一个groupBox,里面有一张图片1。所以我需要在图片1上添加较小的图片2,但图片2的背景不能与图片1重叠。我试过这种方法:InitializeComponent();groupBox.Controls.Add(pictureBox2);pictureBox2.Location = new Point(0, 0);pictureBox2.BackColor = Color.Transparent;和这个InitializeComponent();pictureBox1.Controls.Add(pictureBox2);pictureBox2.Location = new Point(0, 0);pictureBox2.BackColor = Color.Transparent;但都不起作用。
                    
                    
                2 回答
                            撒科打诨
                            
                                
                            
                        
                        
                                                
                    TA贡献1934条经验 获得超2个赞
您需要设置图片框的父控件。显示的透明背景是父控件的透明背景。
InitializeComponent();
groupBox.Controls.Add(pictureBox2);
pictureBox2.Parent = pictureBox1;
pictureBox2.Location = new Point(0, 0);
pictureBox2.BackColor = Color.Transparent;
                            红糖糍粑
                            
                                
                            
                        
                        
                                                
                    TA贡献1815条经验 获得超6个赞
为了实现这一点,请尝试以下操作:
InitializeComponent();
pictureBox1.Controls.Add(pictureBox2);
pictureBox2.Location = new Point(0, 0);
pictureBox2.BackColor = Color.Transparent;
pictureBox1.SendToBack();
pictureBox2.BringToFront();
使用 .SendToBack() 作为背面的,使用 .BringToFront() 作为正面的。
- 2 回答
 - 0 关注
 - 438 浏览
 
添加回答
举报
0/150
	提交
		取消
	