显示面板的按钮

发布于 2024-10-28 23:54:20 字数 1962 浏览 1 评论 0原文

当我尝试在按下按钮时调出面板时,它不会显示。在属性中可见设置为 false。我第一次使用此方法打开面板:

        pnlSettings.Location = new Point(0, 0);
        pnlSettings.Size = this.ClientSize;
        pnlSettings.Visible = true;
        pnlSettings.BringToFront();

该代码在第一次使用时有效。但是,当我尝试使用程序中其他地方的相同代码时,它无法完全工作。

        private void btnSettings_Click(object sender, EventArgs e)
    {
        int valueTemp;

        valueTemp = _game.Settings.GetValue("MusicVolume", 2);
        if (valueTemp < 0) valueTemp = 0;
        if (valueTemp > 3) valueTemp = 3;
        trackMusic.Value = valueTemp;
        valueTemp = _game.Settings.GetValue("SoundFxVolume", 3);
        if (valueTemp < 0) valueTemp = 0;
        if (valueTemp > 3) valueTemp = 3;
        trackSoundFx.Value = valueTemp;

        pnlSettings.Location = new Point(0, 0);
        pnlSettings.Size = this.ClientSize;
        pnlSettings.Visible = true;
        pnlSettings.BringToFront();

        this.Menu = mnuTitleSettings;
    }

上面的代码按照预期的方式工作。然而,以下代码只是暂停游戏并更改菜单。面板设置面板不显示。

        private void mnuMain_Settings_Click(object sender, EventArgs e)
    {
        int valueTemp;

        Pause(true);

        valueTemp = _game.Settings.GetValue("MusicVolume", 2);
        if (valueTemp < 0) valueTemp = 0;
        if (valueTemp > 3) valueTemp = 3;
        trackMusic.Value = valueTemp;
        valueTemp = _game.Settings.GetValue("SoundFxVolume", 3);
        if (valueTemp < 0) valueTemp = 0;
        if (valueTemp > 3) valueTemp = 3;
        trackSoundFx.Value = valueTemp;

        pnlSettings.Location = new Point(0, 0);
        pnlSettings.Size = this.ClientSize;
        pnlSettings.Visible = true;
        pnlSettings.BringToFront();


        this.Menu = mnuSettings;
    }

是否有另一种方法可以显示面板并且仍然保存和更改数据?或者我可以添加一些东西让它显示出来?我尝试添加

        pnlSettings.Show();

仍然没有运气。

预先感谢您的帮助。

When I try to bring up a panel when a button is pressed it does not show up. In properties visible is set to false. I bring up the panel the first time using this method:

        pnlSettings.Location = new Point(0, 0);
        pnlSettings.Size = this.ClientSize;
        pnlSettings.Visible = true;
        pnlSettings.BringToFront();

That code works the first time it is used. But when I try use the same code elsewere in the program it does not fully work.

        private void btnSettings_Click(object sender, EventArgs e)
    {
        int valueTemp;

        valueTemp = _game.Settings.GetValue("MusicVolume", 2);
        if (valueTemp < 0) valueTemp = 0;
        if (valueTemp > 3) valueTemp = 3;
        trackMusic.Value = valueTemp;
        valueTemp = _game.Settings.GetValue("SoundFxVolume", 3);
        if (valueTemp < 0) valueTemp = 0;
        if (valueTemp > 3) valueTemp = 3;
        trackSoundFx.Value = valueTemp;

        pnlSettings.Location = new Point(0, 0);
        pnlSettings.Size = this.ClientSize;
        pnlSettings.Visible = true;
        pnlSettings.BringToFront();

        this.Menu = mnuTitleSettings;
    }

The code above works how it's supposed to. However the following code just pauses the game and changes the menu. The panel settings panel does not show up.

        private void mnuMain_Settings_Click(object sender, EventArgs e)
    {
        int valueTemp;

        Pause(true);

        valueTemp = _game.Settings.GetValue("MusicVolume", 2);
        if (valueTemp < 0) valueTemp = 0;
        if (valueTemp > 3) valueTemp = 3;
        trackMusic.Value = valueTemp;
        valueTemp = _game.Settings.GetValue("SoundFxVolume", 3);
        if (valueTemp < 0) valueTemp = 0;
        if (valueTemp > 3) valueTemp = 3;
        trackSoundFx.Value = valueTemp;

        pnlSettings.Location = new Point(0, 0);
        pnlSettings.Size = this.ClientSize;
        pnlSettings.Visible = true;
        pnlSettings.BringToFront();


        this.Menu = mnuSettings;
    }

Is there another way that I can display the the panel and it still save and change the data? Or is there something I can add to make it display? I have tried adding

        pnlSettings.Show();

Still no luck.

Thank you in advance for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桜花祭 2024-11-04 23:54:20

在将控件添加到父级的 Control 集合之前,该控件不会变得可见。

    pnlSettings.Location = new Point(0, 0);
    pnlSettings.Size = this.ClientSize;
    this.Controls.Add(pnlSettings);

当您再次删除它时,不要忘记调用它的 Dispose() 方法。

A control doesn't become visible until you add it to the parent's Control collection.

    pnlSettings.Location = new Point(0, 0);
    pnlSettings.Size = this.ClientSize;
    this.Controls.Add(pnlSettings);

Don't forget to call its Dispose() method when you remove it again.

顾忌 2024-11-04 23:54:20

您是否在其他地方有从其父级 Controls 集合中删除 pnlSettings 的代码?像这样的东西:

this.Controls.Remove(pnlSettings);

Do you have code elsewhere that removes pnlSettings from its parent's Controls collection? Something like:

this.Controls.Remove(pnlSettings);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文