【发布时间】:2020-01-08 06:50:30
【问题描述】:
我正在使用 3 个图片框。 1 作为背景,2 作为背景上的透明层。所有尺寸相同。第 1 层用于绘制线条,第 2 层用于绘制形状。我正在使用选项卡控件来控制哪个图层可见,哪个图层隐藏。但不知何故不能使两个图层同时可见,即使它们都是透明的。
我正在使用的代码
public Form1()
{
InitializeComponent();
bgLayer.Image = bmp;
bgLayer.Controls.Add(lineLayer);
bgLayer.Controls.Add(squareLayer);
lineLayer.Location = new Point(0, 0);
squareLayer.Location = new Point(0, 0);
lineLayer.BackColor = Color.Transparent;
squareLayer.BackColor = Color.Transparent;
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex == 0)
{
lineLayer.Visible = true;
squareLayer.Visible = true;
lineLayer.Enabled = false;
squareLayer.Enabled = false;
}
else if (tabControl1.SelectedIndex == 1)
{
lineLayer.Visible = true;
squareLayer.Visible = false;
lineLayer.Enabled = true;
squareLayer.Enabled = false;
}
else if (tabControl1.SelectedIndex == 2)
{
lineLayer.Visible = false;
squareLayer.Visible = true;
lineLayer.Enabled = false;
squareLayer.Enabled = true;
}
}
有人知道如何让两个透明层同时可见吗? 选项卡控件 0 都是可见的,1 仅是图片框 1,2 仅是图片框 3。选项卡控件 1 和 2 工作正常,但 0 仅显示图层图片框1。
尝试添加lineLayer.Controls.Add(squareLayer);,但它使程序在执行时缓冲区不停
【问题讨论】:
-
我认为 picturebox1 会覆盖 picturebox3 因为两个位置相同。
-
它们需要被一个一个嵌套。 - 所以将
pictureBox2.Controls.Add(pictureBox3);更改为pictureBox1.Controls.Add(pictureBox3);。但一定要选择一个合理的顺序和命名方案! -
@TaW 之前尝试过,程序在执行时不会停止缓冲。很抱歉文件名很快就会编辑它
-
摆脱你的控制层。只需在一个 PictureBox 控件中完成所有绘画。
-
程序不会停止缓冲 我不知道这是什么意思,但我知道如果操作正确它会起作用..:
pbox3.Parent = pbox2; pbox2.Parent=pbox1; pbox1.Parent = pBoxBase;
标签: c# picturebox