显示面板的按钮
当我尝试在按下按钮时调出面板时,它不会显示。在属性中可见设置为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在将控件添加到父级的 Control 集合之前,该控件不会变得可见。
当您再次删除它时,不要忘记调用它的 Dispose() 方法。
A control doesn't become visible until you add it to the parent's Control collection.
Don't forget to call its Dispose() method when you remove it again.
您是否在其他地方有从其父级
Controls
集合中删除pnlSettings
的代码?像这样的东西:Do you have code elsewhere that removes
pnlSettings
from its parent'sControls
collection? Something like: