【问题标题】:How can I make a background panel from a form transpart/invisible in an XNA window?如何在 XNA 窗口中从表单透明/不可见中制作背景面板?
【发布时间】:2012-03-16 22:39:02
【问题描述】:

我有一个 XNA 项目,它利用 Windows.Forms 创建 GUI。我们的 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 社区

【问题讨论】:

  • 为什么你的面板太大了?让它更小:)

标签: c# winforms user-interface colors xna-4.0


【解决方案1】:

尝试设置面板的Region 属性。您可以手动创建必要的Region 对象(通过枚举描述可见多边形的线)或使用某种方法将具有透明度颜色键的图像转换为Region(轻松谷歌搜索 - 例如https://stackoverflow.com/questions/886968/how-do-i-convert-an-images-transparency-into-a-region)。

由于面板的几何形状似乎不太复杂,您可以按照以下方式手动创建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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    相关资源
    最近更新 更多