[英]How can I make a background panel from a form transpart/invisible in an XNA window?
我有一个利用Windows.Forms创建GUI的XNA项目。 我们的GUI由左面板和右面板组成。 它们都有覆盖的图像(我们称它们为面板图像)。 这些图像上有带有图像的按钮。 现在面板图像不能完全覆盖面板。 现在,我们要做的是使面板不可见或透明,以便您仅看到面板图像。 在下面的图片中,我圈出了我想要透明/不可见的圆圈。 正如您在项目的上部看到的那样,它看起来已经是透明的,但这仅仅是因为它与XNA场景的背景融合在一起。 在面板位于地面上方的底部,您可以看到面板如何比面板图像延伸得更多。 因此,有谁知道我如何使那些部分不可见/透明。
好了,我们把面板颜色设置为Color.Transparent,洋红色(XNA透明颜色),这些尝试都没有用。 任何意见/建议都值得欢迎和赞赏。
这是设置面板的代码:
this.pnlLeftSide.BackgroundImage = global::Referenceator_UI.Resources.LeftBar;
this.pnlLeftSide.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.pnlLeftSide.Controls.Add(this.btnScreenShot);
this.pnlLeftSide.Controls.Add(this.btnScale);
this.pnlLeftSide.Controls.Add(this.btnMove);
this.pnlLeftSide.Controls.Add(this.btnRotate);
this.pnlLeftSide.Controls.Add(this.btnSelect);
this.pnlLeftSide.Location = new System.Drawing.Point(0, 0);
this.pnlLeftSide.Name = "pnlLeftSide";
this.pnlLeftSide.Size = new System.Drawing.Size(197, Screen.PrimaryScreen.WorkingArea.Height);
this.pnlLeftSide.Dock = DockStyle.Left;
this.pnlLeftSide.BackColor = controlColor; //this what we want invisible/transparent
-谢谢stackoverflow社区
尝试设置面板的Region
属性。 您可以手动创建必要的Region
对象(通过枚举描述可见多边形的线),也可以使用某种方法将具有透明色键的图像转换为Region
(很容易用Google搜索-https: //stackoverflow.com/questions/886968/how-do-i-例如,将图像透明度转换为区域 )。
由于面板的几何形状似乎不太复杂,因此可以按照以下方式手动创建Region
:
using(var gp = new System.Drawing.Drawing2D.GraphicsPath())
{
// Here goes series of AddLine() calls.
// You must
// gp.AddLine(0, 0, leftPanel.Width, 0);
// ...
gp.CloseFigure();
return new Region(gp);
}
请注意,即使使用此方法,您也会获得清晰的边缘。 考虑使用XNA渲染所有的GUI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.