PckManager - Prevented re-creating same panel

This commit is contained in:
miku-666
2023-06-03 19:15:45 +02:00
parent 33c8431276
commit e005c31cb2
2 changed files with 8 additions and 7 deletions

View File

@@ -76,7 +76,7 @@
this.supportedPlatformComboBox.TabIndex = 0;
this.supportedPlatformComboBox.Theme = MetroFramework.MetroThemeStyle.Dark;
this.supportedPlatformComboBox.UseSelectable = true;
this.supportedPlatformComboBox.SelectedIndexChanged += new System.EventHandler(this.supportedPlatformComboBox_SelectedIndexChanged);
this.supportedPlatformComboBox.SelectionChangeCommitted += new System.EventHandler(this.supportedPlatformComboBox_SelectionChangeCommitted);
//
// mainPanel
//

View File

@@ -23,6 +23,7 @@ namespace PckStudio.Features
public partial class PckManager : MetroFramework.Forms.MetroForm
{
private Control currentlyShowingControl;
private string currentlyShowingControlName;
private const string CemU = "Cemu";
// TODO: Implement these Panels
@@ -49,22 +50,22 @@ namespace PckStudio.Features
currentlyShowingControl?.Focus();
}
private void supportedPlatformComboBox_SelectedIndexChanged(object sender, EventArgs e)
private void supportedPlatformComboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
mainPanel.Controls.Remove(currentlyShowingControl);
if (supportedPlatformComboBox.SelectedIndex > -1)
if (!supportedPlatformComboBox.SelectedItem.Equals(currentlyShowingControlName))
{
string text = supportedPlatformComboBox.Items[supportedPlatformComboBox.SelectedIndex].ToString();
mainPanel.Controls.Remove(currentlyShowingControl);
currentlyShowingControlName = supportedPlatformComboBox.Items[supportedPlatformComboBox.SelectedIndex].ToString();
try
{
currentlyShowingControl = text switch
currentlyShowingControl = currentlyShowingControlName switch
{
CemU => new CemuPanel(),
//WiiU => new WiiUPanel(),
//PS3 => throw new NotImplementedException($"{text}-Panel is currently not implemented."),
//PSVita => throw new NotImplementedException($"{text}-Panel is currently not implemented."),
//RPCS3 => throw new NotImplementedException($"{text}-Panel is currently not implemented."),
_ => throw new Exception($"No Panel found for: {text}"),
_ => throw new Exception($"No Panel found for: {currentlyShowingControlName}"),
};
currentlyShowingControl.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right;
mainPanel.SetColumnSpan(currentlyShowingControl, 2);