private void Form_LostFocus(object sender, EventArgs e) { form.BringToFront(); form.Activate(); form.Hide(); LostFocus(this); }
/// <summary> /// Called when the parent is shown. /// </summary> void _parentShown(object sender, System.EventArgs e) { try { _documentNew = CadKit.Plugins.Manager.Instance.getAll <CadKit.Interfaces.IDocumentNew>(); for (uint i = 0; i < _documentNew.Length; ++i) { CadKit.Documents.Document doc = this._createDocument(i); CadKit.Interfaces.IDocument iDoc = doc as CadKit.Interfaces.IDocument; if (null != doc && null != iDoc) { System.Windows.Forms.LinkLabel label = new System.Windows.Forms.LinkLabel(); label.Name = iDoc.TypeName; label.Text = iDoc.TypeName; label.Click += new System.EventHandler(_labelClick); CadKit.Interfaces.IDocumentIcon docIcon = iDoc as CadKit.Interfaces.IDocumentIcon; if (docIcon == null || docIcon.Icon == null) { label.Image = CadKit.Images.Image.load(CadKit.Helios.Application.Instance.IconDir + "/new_document.png"); } else { label.Image = docIcon.Icon as System.Drawing.Image; } label.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; _flowLayoutPanel.Controls.Add(label); } doc = null; } System.Windows.Forms.Form parent = sender as System.Windows.Forms.Form; CadKit.Tools.ToolWindow.configure(this, parent, "New Document", false); _configureDockWindow(sender, this); CadKit.Interfaces.IWindowMenu windowMenu = sender as CadKit.Interfaces.IWindowMenu; if (null != windowMenu) { windowMenu.addFormWindowMenu(this.Text, this); } parent.Activate(); } catch (System.Exception ex) { System.Console.WriteLine("Error 3980677532: building new document form: {0}", ex.Message); } }
/// <summary> /// Bring the view forward. /// </summary> private void _activateView(CadKit.Interfaces.IDocumentView view) { System.Windows.Forms.Form form = view as System.Windows.Forms.Form; if (null != form) { if (true == form.InvokeRequired) { form.BeginInvoke(new VoidReturnZeroArgumentsDelegate(form.Activate)); } else { form.Activate(); } } }
public static void ForceWindowFocus(System.Windows.Forms.Form objForm, int intTimeoutMilliseconds = 1000) { int tA, tB; tA = System.Environment.TickCount; tB = System.Environment.TickCount; IntPtr ip = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; while (((tB - tA) < intTimeoutMilliseconds) && Native.GetForegroundWindow() == ip) { objForm.TopMost = true; objForm.TopMost = false; objForm.Activate(); //Native.SwitchToThisWindow(ip, true); // Native.SetForegroundWindow(ip); System.Windows.Forms.Application.DoEvents(); } }
/* ----------------------------------------------------------------- */ /// /// SetTopMost /// /// <summary> /// フォームを最前面に表示します。 /// </summary> /// /// <param name="form">フォーム</param> /// <param name="active">アクティブ状態にするかどうか</param> /// /// <remarks> /// SetTopMost は主に、フォーカスを奪わずに最前面に表示する時に /// 使用します。この場合、最前面に表示された状態でも TopMost /// プロパティは false となります。 /// </remarks> /// /* ----------------------------------------------------------------- */ public static void SetTopMost(this System.Windows.Forms.Form form, bool active) { if (active) { form.TopMost = true; form.Activate(); } else { const uint SWP_NOSIZE = 0x0001; const uint SWP_NOMOVE = 0x0002; const uint SWP_NOACTIVATE = 0x0010; const uint SWP_NOSENDCHANGING = 0x0400; User32.NativeMethods.SetWindowPos(form.Handle, (IntPtr)(-1), /* HWND_TOPMOST */ 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE ); } }
public void OnWndProc(System.Windows.Forms.Form form, int m, IntPtr wParam, IntPtr lParam, bool activate) { if (form == null) { throw new ArgumentNullException("form"); } if (m == Message) { if (activate) { if (form.WindowState == System.Windows.Forms.FormWindowState.Minimized) { form.WindowState = System.Windows.Forms.FormWindowState.Normal; } form.Activate(); FormUtilities.ActivateWindow(FormUtilities.GetModalWindow(form.Handle)); } } }
/// <summary> /// Called when parent form is shown. /// </summary> private void _parentShown(object sender, System.EventArgs args) { try { CadKit.Plugins.Windows.Properties.Editor editor = new CadKit.Plugins.Windows.Properties.Editor(); System.Windows.Forms.Form parent = sender as System.Windows.Forms.Form; Component._configureDockWindow(sender, editor); CadKit.Interfaces.IWindowMenu windowMenu = sender as CadKit.Interfaces.IWindowMenu; if (null != windowMenu) { windowMenu.addFormWindowMenu(editor.Text, editor); } parent.Activate(); } catch (System.Exception e) { System.Console.WriteLine("Error 3209302884: {0}", e.Message); } }
/// <summary> /// Called when parent form is shown. /// </summary> private void _parentShown(object sender, System.EventArgs args) { try { CadKit.Plugins.Windows.SnapShot.SnapShotWindow form = new CadKit.Plugins.Windows.SnapShot.SnapShotWindow(); System.Windows.Forms.Form parent = sender as System.Windows.Forms.Form; Component._configureDockWindow(sender, form); CadKit.Interfaces.IWindowMenu windowMenu = sender as CadKit.Interfaces.IWindowMenu; if (null != windowMenu) { windowMenu.addFormWindowMenu(form.Text, form); } parent.Activate(); } catch (System.Exception e) { System.Console.WriteLine("Error 1771862310: {0}", e.Message); } }
/// <summary> /// Called when parent form is shown. /// </summary> private void _parentShown(object sender, System.EventArgs args) { try { CadKit.Plugins.LayerManager.Layers form = new CadKit.Plugins.LayerManager.Layers(); System.Windows.Forms.Form parent = sender as System.Windows.Forms.Form; CadKit.Tools.ToolWindow.configure(form, parent, "Layers", false); _configureDockWindow(sender, form); CadKit.Interfaces.IWindowMenu windowMenu = sender as CadKit.Interfaces.IWindowMenu; if (null != windowMenu) { windowMenu.addFormWindowMenu(form.Text, form); } parent.Activate(); } catch (System.Exception e) { System.Console.WriteLine("Error 2363874639: {0}", e.Message); } }
/// <summary> /// Create <see cref="System.Windows.Forms.Form"/> and <see cref="IRenderHost"/> for it. /// </summary> private static IRenderHost CreateWindowForm(System.Drawing.Size size, string title, Func <IntPtr, IRenderHost> ctorRenderHost) { var window = new System.Windows.Forms.Form { Size = size, Text = title, }; var hostControl = new System.Windows.Forms.Panel { Dock = System.Windows.Forms.DockStyle.Fill, BackColor = System.Drawing.Color.Transparent, ForeColor = System.Drawing.Color.Transparent, }; window.Controls.Add(hostControl); // fix mouse wheel hostControl.MouseEnter += (sender, args) => { if (System.Windows.Forms.Form.ActiveForm != window) { window.Activate(); } if (!hostControl.Focused) { hostControl.Focus(); } }; window.Closed += (sender, args) => System.Windows.Application.Current.Shutdown(); window.Show(); return(ctorRenderHost(hostControl.Handle())); }
/* ----------------------------------------------------------------- */ /// /// BringToFront /// /// <summary> /// フォームを最前面に表示します。 /// </summary> /// /// <param name="form">フォーム</param> /// /* ----------------------------------------------------------------- */ public static void BringToFront(this System.Windows.Forms.Form form) { form.ResetTopMost(); form.Activate(); }