using PaintDotNet.Instrument; using System; using System.Windows.Forms; namespace PaintDotNet { class FloatingFormMethod { /// /// 显示浮动窗口 /// /// 获取已经弹出的窗口对象 /// 没有弹出的窗口对象则创建 /// AppWorkspace的引用 public static void ShowFloatForm(Form form, FloatingToolForm af, AppWorkspace workspace,bool isLeft = false) { new FloatingFormMethod(workspace).ShowFloatForm(form, af, isLeft); } /// /// AppWorkspace的引用 /// private AppWorkspace appWorkspace; private FloatingFormMethod(AppWorkspace workspace) { this.appWorkspace = workspace; } /// /// 显示浮动窗口 /// /// 获取已经弹出的窗口对象 /// 没有弹出的窗口对象则创建 private void ShowFloatForm(Form form, FloatingToolForm af,bool isLeft = false) { if (form == null || form.IsDisposed) { if (af == null) return; SnapObstacle obstacle = af.SnapObstacle; SnapManager sm = SnapManager.FindMySnapManager(this.appWorkspace); if (sm != null && obstacle.EnableSave) { try { if (isLeft) { sm.ParkObstacle(af, this.appWorkspace, HorizontalSnapEdge.Top, VerticalSnapEdge.Left); } else { sm.LoadSnapObstacleData(SystemLayer.Settings.CurrentUser, obstacle); } } catch (Exception) { sm.ParkObstacle(af, this.appWorkspace, HorizontalSnapEdge.Top, VerticalSnapEdge.Right); } af.FormClosing += Af_FormClosing; } else sm.ParkObstacle(af, this.appWorkspace, HorizontalSnapEdge.Top, VerticalSnapEdge.Right); //af.StartPosition = FormStartPosition.CenterScreen; Form mainForm = appWorkspace.FindForm(); if (mainForm != null) //mainForm.Activate(); af.Show(mainForm/*MainForm.ActiveForm*/); //af.Activate(); //af.WindowState = FormWindowState.Normal; //if (PdnResources.GetString("Menu.Tools.ImageIndex.Text").Equals(af.Text)) //{ // if (ImageIndexDialog.imageIndexDialog != null) // { // //ImageIndexDialog.imageIndexDialog.fromMaxSize = ImageIndexDialog.imageIndexDialog.Width; // af.Visible = false; // af.Width = 834; // af.Width = ImageIndexDialog.imageIndexDialog.splitContainer1.Panel1.Width + 24; // af.Visible = true; // } //} } else { form.Activate(); form.WindowState = FormWindowState.Normal; } } /// /// 浮动窗口消失时保存窗口位置信息 /// /// /// private void Af_FormClosing(object sender, FormClosingEventArgs e) { SnapObstacle obstacle = ((FloatingToolForm)sender).SnapObstacle; SnapManager sm = SnapManager.FindMySnapManager(this.appWorkspace); if (sm != null && obstacle.EnableSave) sm.SaveSnapObstacleData(SystemLayer.Settings.CurrentUser, obstacle); } } }