FloatingFormMethod.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using PaintDotNet.Instrument;
  2. using System;
  3. using System.Windows.Forms;
  4. namespace PaintDotNet
  5. {
  6. class FloatingFormMethod
  7. {
  8. /// <summary>
  9. /// 显示浮动窗口
  10. /// </summary>
  11. /// <param name="form">获取已经弹出的窗口对象</param>
  12. /// <param name="af">没有弹出的窗口对象则创建</param>
  13. /// <param name="workspace">AppWorkspace的引用</param>
  14. public static void ShowFloatForm(Form form, FloatingToolForm af, AppWorkspace workspace,bool isLeft = false)
  15. {
  16. new FloatingFormMethod(workspace).ShowFloatForm(form, af, isLeft);
  17. }
  18. /// <summary>
  19. /// AppWorkspace的引用
  20. /// </summary>
  21. private AppWorkspace appWorkspace;
  22. private FloatingFormMethod(AppWorkspace workspace)
  23. {
  24. this.appWorkspace = workspace;
  25. }
  26. /// <summary>
  27. /// 显示浮动窗口
  28. /// </summary>
  29. /// <param name="form">获取已经弹出的窗口对象</param>
  30. /// <param name="af">没有弹出的窗口对象则创建</param>
  31. private void ShowFloatForm(Form form, FloatingToolForm af,bool isLeft = false)
  32. {
  33. if (form == null || form.IsDisposed)
  34. {
  35. if (af == null)
  36. return;
  37. SnapObstacle obstacle = af.SnapObstacle;
  38. SnapManager sm = SnapManager.FindMySnapManager(this.appWorkspace);
  39. if (sm != null && obstacle.EnableSave)
  40. {
  41. try
  42. {
  43. if (isLeft)
  44. {
  45. sm.ParkObstacle(af, this.appWorkspace, HorizontalSnapEdge.Top, VerticalSnapEdge.Left);
  46. }
  47. else
  48. {
  49. sm.LoadSnapObstacleData(SystemLayer.Settings.CurrentUser, obstacle);
  50. }
  51. }
  52. catch (Exception)
  53. {
  54. sm.ParkObstacle(af, this.appWorkspace, HorizontalSnapEdge.Top, VerticalSnapEdge.Right);
  55. }
  56. af.FormClosing += Af_FormClosing;
  57. }
  58. else
  59. sm.ParkObstacle(af, this.appWorkspace, HorizontalSnapEdge.Top, VerticalSnapEdge.Right);
  60. //af.StartPosition = FormStartPosition.CenterScreen;
  61. Form mainForm = appWorkspace.FindForm();
  62. if (mainForm != null)
  63. //mainForm.Activate();
  64. af.Show(mainForm/*MainForm.ActiveForm*/);
  65. //af.Activate();
  66. //af.WindowState = FormWindowState.Normal;
  67. //if (PdnResources.GetString("Menu.Tools.ImageIndex.Text").Equals(af.Text))
  68. //{
  69. // if (ImageIndexDialog.imageIndexDialog != null)
  70. // {
  71. // //ImageIndexDialog.imageIndexDialog.fromMaxSize = ImageIndexDialog.imageIndexDialog.Width;
  72. // af.Visible = false;
  73. // af.Width = 834;
  74. // af.Width = ImageIndexDialog.imageIndexDialog.splitContainer1.Panel1.Width + 24;
  75. // af.Visible = true;
  76. // }
  77. //}
  78. }
  79. else
  80. {
  81. form.Activate();
  82. form.WindowState = FormWindowState.Normal;
  83. }
  84. }
  85. /// <summary>
  86. /// 浮动窗口消失时保存窗口位置信息
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void Af_FormClosing(object sender, FormClosingEventArgs e)
  91. {
  92. SnapObstacle obstacle = ((FloatingToolForm)sender).SnapObstacle;
  93. SnapManager sm = SnapManager.FindMySnapManager(this.appWorkspace);
  94. if (sm != null && obstacle.EnableSave)
  95. sm.SaveSnapObstacleData(SystemLayer.Settings.CurrentUser, obstacle);
  96. }
  97. }
  98. }