TabControl.TabPage.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Drawing;
  2. namespace System.Windows.Forms
  3. {
  4. public class TabPage : ContainerControl
  5. {
  6. protected new System.Windows.Controls.TabItem control { get; }
  7. public override string Text
  8. {
  9. get => control.Header?.ToString();
  10. set => control.Header = value;
  11. }
  12. public bool UseVisualStyleBackColor { get; set; }
  13. // WPF TabItem control is just a "tab" (not a container for its child controls), so its location/size should not be changed.
  14. protected override void SetControlLeft(int value) { }
  15. protected override void SetControlTop(int value) { }
  16. protected override void SetControlWidth(int value) { }
  17. protected override void SetControlHeight(int value) { }
  18. // return actual bounding rectangle to make layout engine working (case: FR QueryBuilder in pmV2)
  19. public override Rectangle DisplayRectangle =>
  20. container.ActualWidth == 0 ?
  21. base.DisplayRectangle :
  22. new Rectangle(0, 0, (int)(container.ActualWidth * DpiScale), (int)(container.ActualHeight * DpiScale));
  23. private void EnumControls(Control control, Action<Control> action)
  24. {
  25. action(control);
  26. foreach (Control c in control.Controls)
  27. EnumControls(c, action);
  28. }
  29. public TabPage()
  30. {
  31. control = new();
  32. SetContentControl(control);
  33. control.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
  34. control.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
  35. // the actual container for tab's child controls is this.container so we need to watch its size
  36. control.SizeChanged -= Size_Changed;
  37. container.SizeChanged += (s, e) =>
  38. {
  39. container.Dispatcher.InvokeAsync(() =>
  40. {
  41. // fix issues with pmV2: refresh controls when tab page becomes active and its dpi is changed (case: FR chart editor)
  42. EnumControls(this, c => c.Refresh());
  43. });
  44. Size_Changed(s, e);
  45. };
  46. }
  47. }
  48. }