|
1 | | -#region BSD License |
| 1 | +#region BSD License |
2 | 2 | /* |
3 | 3 | * |
4 | 4 | * Original BSD 3-Clause License (https://github.com/ComponentFactory/Krypton/blob/master/LICENSE) |
@@ -66,6 +66,7 @@ protected class CachedCellState |
66 | 66 | private readonly EventHandler _visibleUpdate; |
67 | 67 | private bool _awaitingFocusUpdate; |
68 | 68 | private bool _awaitingVisibleUpdate; |
| 69 | + private bool _pendingVisibleUpdateOnHandle; |
69 | 70 | private bool _setFocus; |
70 | 71 | private string _closeTooltip; |
71 | 72 | private string _pinTooltip; |
@@ -243,14 +244,24 @@ public void UpdateVisible(bool focus) |
243 | 244 | // Cache focus update until invoke occurs |
244 | 245 | _setFocus = focus; |
245 | 246 |
|
246 | | - // No point requesting the update more than once |
247 | | - if (!_awaitingVisibleUpdate && IsHandleCreated) |
| 247 | + if (IsHandleCreated) |
248 | 248 | { |
249 | | - // Async invoke ensures the delegate is called in sync with the message queue, this means that all the |
250 | | - // layout changes for the space control will be finished and so then we can update the visible state of |
251 | | - // the cells to reflect the tab visible changes. |
252 | | - BeginInvoke(_visibleUpdate); |
253 | | - _awaitingVisibleUpdate = true; |
| 249 | + // No point requesting the update more than once |
| 250 | + if (!_awaitingVisibleUpdate) |
| 251 | + { |
| 252 | + // Async invoke ensures the delegate is called in sync with the message queue, this means that all the |
| 253 | + // layout changes for the space control will be finished and so then we can update the visible state of |
| 254 | + // the cells to reflect the tab visible changes. |
| 255 | + BeginInvoke(_visibleUpdate); |
| 256 | + _awaitingVisibleUpdate = true; |
| 257 | + } |
| 258 | + } |
| 259 | + else |
| 260 | + { |
| 261 | + // The control has no window handle yet (e.g. form is hidden during config load). |
| 262 | + // Defer the visible update until the handle is created so that cell visibility |
| 263 | + // and layout are correctly applied once the form becomes visible. |
| 264 | + _pendingVisibleUpdateOnHandle = true; |
254 | 265 | } |
255 | 266 | } |
256 | 267 | } |
@@ -353,6 +364,23 @@ public override void WritePageElement(XmlWriter xmlWriter, KryptonPage page) |
353 | 364 | /// </summary> |
354 | 365 | protected virtual bool ApplyDockingVisibility => true; |
355 | 366 |
|
| 367 | + /// <summary> |
| 368 | + /// Overridden to apply any pending visible update that was deferred because the handle |
| 369 | + /// did not exist when <see cref="UpdateVisible(bool)"/> was called (e.g. the form was |
| 370 | + /// hidden while a docking configuration was being loaded). |
| 371 | + /// </summary> |
| 372 | + /// <param name="e">An EventArgs containing the event data.</param> |
| 373 | + protected override void OnHandleCreated(EventArgs e) |
| 374 | + { |
| 375 | + base.OnHandleCreated(e); |
| 376 | + |
| 377 | + if (_pendingVisibleUpdateOnHandle) |
| 378 | + { |
| 379 | + _pendingVisibleUpdateOnHandle = false; |
| 380 | + UpdateVisible(_setFocus); |
| 381 | + } |
| 382 | + } |
| 383 | + |
356 | 384 | /// <summary> |
357 | 385 | /// Raises the CellGainsFocus event. |
358 | 386 | /// </summary> |
|
0 commit comments