Skip to content

Commit

Permalink
Active split not selected properly on application start when further …
Browse files Browse the repository at this point in the history
…tabs are created

Reason: If the tab is not selected after creation, the control's initialization is postponed!
           "Controls contained in a TabPage are not created until the tab page is shown,
           and any data bindings in these controls are not activated until the tab page is shown."
           Microsoft - https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.tabpage?view=netframework-4.8
  • Loading branch information
topeterk committed Oct 18, 2019
1 parent 3881d83 commit 705466b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions Sources/ProfileTabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ private void MouseMoveHandler(object sender, MouseEventArgs e)

#region Profile related implementation

public bool InitDone = false;

public void InitializeProfileTabControl()
{
SelectedProfileViewControl = ProfileViewControls[0]; // the only one created by designer
Expand Down Expand Up @@ -187,7 +189,10 @@ public int IndexOf(ProfileViewControl pvc)

/// <summary>
/// Creates a new ProfileViewControl in a new tab.
/// For user controlled tab creation use ProfileTabCreateAndSelect instead!
/// Reminder: If the tab is not selected after creation, the control's initialization is postponed!
/// "Controls contained in a TabPage are not created until the tab page is shown,
/// and any data bindings in these controls are not activated until the tab page is shown."
/// Microsoft - https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.tabpage?view=netframework-4.8
/// </summary>
/// <returns>Created instance</returns>
public ProfileViewControl ProfileTabCreate()
Expand Down Expand Up @@ -302,7 +307,7 @@ public void TabSelectingHandler(object sender, TabControlCancelEventArgs e)
return;
}

if (!SuccessionActive) // Show initial warning message only when succession is not already active
if (!SuccessionActive && InitDone) // Show initial warning message only when succession is not already active (and not during initialization)
{
DialogResult result = MessageBox.Show(
"Opening further tabs combine multiple profiles into one run. " +
Expand Down
3 changes: 2 additions & 1 deletion Sources/ProfilesControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void InitializeProfilesControl(Profiles profiles, Succession Succession)

// As the designer is used, we have at least one tab already existing, so only further tabs must be created
for (int i = 1; i < succession.SuccessionList.Count; i++)
ptc.ProfileTabCreate();
ptc.ProfileTabCreateAndSelect();

// Load profile lists into all tabs and select previous selected profiles
for (int i = 0; i < succession.SuccessionList.Count; i++)
Expand All @@ -153,6 +153,7 @@ public void InitializeProfilesControl(Profiles profiles, Succession Succession)

// Select the last user selected tab
ptc.SelectTab(succession.ActiveIndex);
ptc.InitDone = true;

Ready = true;
}
Expand Down

0 comments on commit 705466b

Please sign in to comment.