【发布时间】:2014-09-14 04:31:16
【问题描述】:
我的表格如下图所示。
我想通过label2查看label1和label3。 (我只想看到label2的边框)。我已将 label2 中的 BackColor 更改为透明。但是结果和上图一样。
【问题讨论】:
-
假设 Winforms:可悲的事实是:这是不可能的。(除非您自己绘制它 - 即便如此,也仅限于像您这样的简单案例......)跨度>
我的表格如下图所示。
我想通过label2查看label1和label3。 (我只想看到label2的边框)。我已将 label2 中的 BackColor 更改为透明。但是结果和上图一样。
【问题讨论】:
在 Windows 窗体中,您不能直接执行此操作。您可以使用BackgroundImage。
试试这个:
void TransparetBackground(Control C)
{
C.Visible = false;
C.Refresh();
Application.DoEvents();
Rectangle screenRectangle = RectangleToScreen(this.ClientRectangle);
int titleHeight = screenRectangle.Top - this.Top;
int Right = screenRectangle.Left - this.Left;
Bitmap bmp = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bmp, new Rectangle(0, 0, this.Width, this.Height));
Bitmap bmpImage = new Bitmap(bmp);
bmp = bmpImage.Clone(new Rectangle(C.Location.X+Right, C.Location.Y + titleHeight, C.Width, C.Height), bmpImage.PixelFormat);
C.BackgroundImage = bmp;
C.Visible = true;
}
在 Form_Load 中:
private void Form1_Load(object sender, EventArgs e)
{
TransparetBackground(label2);
}
你可以看到这个结果:
【讨论】: