public static WIP Show(Control parent) { WIP o = new WIP(); o.Location = Point.Empty; o.Size = parent.ClientSize; o.Parent = parent; o.Show(); o.BringToFront(); o.Update(); parent.Update(); return o; }
/// <summary> /// Initializes an instance of the DisposableCursor class with the specified cursor displayed for the specified control. /// </summary> /// <param name="control">The control to display the cursor over.</param> /// <param name="newCursor">The cursor to display while the mouse pointer is over the control.</param> public DisposableCursor(Control control, Cursor newCursor) { if (control == null) throw new ArgumentNullException(nameof(control)); if (newCursor == null) throw new ArgumentNullException(nameof(newCursor)); this.previousCursor = control.Cursor; this.control = control; control.Cursor = newCursor; control.Update(); }
public static void ValidateControl(Control c, bool passedValidation) { if (!passedValidation) { c.BackColor = Color.Yellow; } else { c.BackColor = Color.White; } c.Update(); }
string SetTextBoxText(Control textbox, string strText) { string strOldText = textbox.Text; textbox.Text = strText; textbox.Update(); return strOldText; }
// 线程安全版本 string Safe_SetTextBoxText(Control textbox, string strText) { if (textbox.Parent != null && textbox.Parent.InvokeRequired) { Delegate_SetTextBoxText d = new Delegate_SetTextBoxText(SetTextBoxText); return (string)textbox.Parent.Invoke(d, new object[] { textbox, strText }); } else { string strOldText = textbox.Text; textbox.Text = strText; textbox.Update(); return strOldText; } }
protected virtual void Update(Control containerControl) { if (containerControl.InvokeRequired) containerControl.BeginInvoke(new MethodInvoker(delegate { containerControl.Update(); })); else containerControl.Update(); }
public void TestPublicMethods () { // Public Methods that force Handle creation: // - CreateControl () // - CreateGraphics () // - GetChildAtPoint () // - Invoke, BeginInvoke throws InvalidOperationException if Handle has not been created // - PointToClient () // - PointToScreen () // - RectangleToClient () // - RectangleToScreen () Control c = new Control (); c.BringToFront (); Assert.IsFalse (c.IsHandleCreated, "A1"); c.Contains (new Control ()); Assert.IsFalse (c.IsHandleCreated, "A2"); c.CreateControl (); Assert.IsTrue (c.IsHandleCreated, "A3"); c = new Control (); Graphics g = c.CreateGraphics (); g.Dispose (); Assert.IsTrue (c.IsHandleCreated, "A4"); c = new Control (); c.Dispose (); Assert.IsFalse (c.IsHandleCreated, "A5"); c = new Control (); //DragDropEffects d = c.DoDragDrop ("yo", DragDropEffects.None); //Assert.IsFalse (c.IsHandleCreated, "A6"); //Assert.AreEqual (DragDropEffects.None, d, "A6b"); //Bitmap b = new Bitmap (100, 100); //c.DrawToBitmap (b, new Rectangle (0, 0, 100, 100)); //Assert.IsFalse (c.IsHandleCreated, "A7"); //b.Dispose (); c.FindForm (); Assert.IsFalse (c.IsHandleCreated, "A8"); c.Focus (); Assert.IsFalse (c.IsHandleCreated, "A9"); c.GetChildAtPoint (new Point (10, 10)); Assert.IsTrue (c.IsHandleCreated, "A10"); c.GetContainerControl (); c = new Control (); Assert.IsFalse (c.IsHandleCreated, "A11"); c.GetNextControl (new Control (), true); Assert.IsFalse (c.IsHandleCreated, "A12"); #if NET_2_0 c.GetPreferredSize (Size.Empty); Assert.IsFalse (c.IsHandleCreated, "A13"); #endif c.Hide (); Assert.IsFalse (c.IsHandleCreated, "A14"); c.Invalidate (); Assert.IsFalse (c.IsHandleCreated, "A15"); //c.Invoke (new InvokeDelegate (InvokeMethod)); //Assert.IsFalse (c.IsHandleCreated, "A16"); c.PerformLayout (); Assert.IsFalse (c.IsHandleCreated, "A17"); c.PointToClient (new Point (100, 100)); Assert.IsTrue (c.IsHandleCreated, "A18"); c = new Control (); c.PointToScreen (new Point (100, 100)); Assert.IsTrue (c.IsHandleCreated, "A19"); c = new Control (); //c.PreProcessControlMessage ??? //c.PreProcessMessage ??? c.RectangleToClient (new Rectangle (0, 0, 100, 100)); Assert.IsTrue (c.IsHandleCreated, "A20"); c = new Control (); c.RectangleToScreen (new Rectangle (0, 0, 100, 100)); Assert.IsTrue (c.IsHandleCreated, "A21"); c = new Control (); c.Refresh (); Assert.IsFalse (c.IsHandleCreated, "A22"); c.ResetBackColor (); Assert.IsFalse (c.IsHandleCreated, "A23"); c.ResetBindings (); Assert.IsFalse (c.IsHandleCreated, "A24"); c.ResetCursor (); Assert.IsFalse (c.IsHandleCreated, "A25"); c.ResetFont (); Assert.IsFalse (c.IsHandleCreated, "A26"); c.ResetForeColor (); Assert.IsFalse (c.IsHandleCreated, "A27"); c.ResetImeMode (); Assert.IsFalse (c.IsHandleCreated, "A28"); c.ResetRightToLeft (); Assert.IsFalse (c.IsHandleCreated, "A29"); c.ResetText (); Assert.IsFalse (c.IsHandleCreated, "A30"); c.SuspendLayout (); Assert.IsFalse (c.IsHandleCreated, "A31"); c.ResumeLayout (); Assert.IsFalse (c.IsHandleCreated, "A32"); #if NET_2_0 c.Scale (new SizeF (1.5f, 1.5f)); Assert.IsFalse (c.IsHandleCreated, "A33"); #endif c.Select (); Assert.IsFalse (c.IsHandleCreated, "A34"); c.SelectNextControl (new Control (), true, true, true, true); Assert.IsFalse (c.IsHandleCreated, "A35"); c.SetBounds (0, 0, 100, 100); Assert.IsFalse (c.IsHandleCreated, "A36"); c.Update (); Assert.IsFalse (c.IsHandleCreated, "A37"); }
protected bool TrackHandle(int nHandle,Control frm,Point point,Form frmClipTo) { Debug.Assert(nHandle >= 0); Debug.Assert(nHandle <= 8); // handle 8 is inside the rect // don't handle if capture already set //if(frm.Capture) return false; Debug.Assert(!m_bFinalErase); // save original width & height in pixels int nWidth = m_rect.Width; int nHeight = m_rect.Height; // set capture to the window which received this message frm.Capture=true; Debug.Assert(frm.Capture); frm.Update(); if (frmClipTo!=null) frmClipTo.Update(); Rectangle rectSave = m_rect; // find out what x/y coords we are supposed to modify int px=0, py=0; int xDiff=0, yDiff=0; GetModifyPointers(nHandle,ref px,ref py,ref xDiff,ref yDiff,true); xDiff = point.X - xDiff; yDiff = point.Y - yDiff; // get DC for drawing Graphics gs; if (frmClipTo!=null) { // clip to arbitrary window by using adjusted Window DC gs=frmClipTo.CreateGraphics(); } else { // otherwise, just use normal DC gs=frm.CreateGraphics(); } Rectangle rectOld; bool bMoved = false; // get messages until capture lost or cancelled/accepted for (;;) { MSG msg=new MSG(); if(GetMessage(ref msg, 0, 0, 0)!=1) break; if(!frm.Capture) break; switch (msg.message) { // handle movement/accept messages case WM_LBUTTONUP: case WM_MOUSEMOVE: rectOld = m_rect; // handle resize cases (and part of move) SetRectInt(px,LoWord(msg.lParam) - xDiff); SetRectInt(py,HiWord(msg.lParam) - yDiff); // handle move case if (nHandle == (int)TrackerHit.hitMiddle) { m_rect.Width=nWidth; m_rect.Height=nHeight; } // allow caller to adjust the rectangle if necessary AdjustRect(nHandle,ref m_rect); // only redraw and callback if the rect actually changed! m_bFinalErase = (msg.message == WM_LBUTTONUP); if (m_bFinalErase) goto ExitLoop; if (!rectOld.Equals(m_rect) || m_bFinalErase) { if (bMoved) { m_bErase = true; DrawTrackerRect(rectOld, frmClipTo, gs, frm); } OnChangedRect(rectOld); if (msg.message != WM_LBUTTONUP) bMoved = true; } if (m_bFinalErase) goto ExitLoop; if (!rectOld.Equals(m_rect)) { m_bErase = false; DrawTrackerRect(m_rect, frmClipTo, gs, frm); } break; // handle cancel messages case WM_KEYDOWN: if (msg.wParam != 0x1B)//VK_ESCAPE break; goto default; case WM_RBUTTONDOWN: if (bMoved) { m_bErase = m_bFinalErase = true; DrawTrackerRect(m_rect, frmClipTo, gs, frm); } m_rect = rectSave; goto ExitLoop; // just dispatch rest of the messages default: DispatchMessage(ref msg); break; } } ExitLoop: gs.Dispose(); frm.Capture=false; // restore rect in case bMoved is still FALSE if (!bMoved) m_rect = rectSave; m_bFinalErase = false; m_bErase = false; // return TRUE only if rect has changed return !rectSave.Equals(m_rect); }
internal void AddControl(Control newChild, IDictionary defaultValues) { Point empty = Point.Empty; Size size = Size.Empty; Size size2 = new Size(0, 0); bool flag = (defaultValues != null) && defaultValues.Contains("Location"); bool flag2 = (defaultValues != null) && defaultValues.Contains("Size"); if (flag) { empty = (Point) defaultValues["Location"]; } if (flag2) { size = (Size) defaultValues["Size"]; } if ((defaultValues != null) && defaultValues.Contains("Offset")) { size2 = (Size) defaultValues["Offset"]; } IDesignerHost host = (IDesignerHost) this.GetService(typeof(IDesignerHost)); if ((((host != null) && (newChild != null)) && (!this.Control.Contains(newChild) && (host.GetDesigner(newChild) is ControlDesigner))) && (!(newChild is Form) || !((Form) newChild).TopLevel)) { Rectangle dragRect = new Rectangle(); if (flag) { empty = this.Control.PointToClient(empty); dragRect.X = empty.X; dragRect.Y = empty.Y; } else { ISelectionService service = (ISelectionService) this.GetService(typeof(ISelectionService)); object primarySelection = service.PrimarySelection; Control controlForComponent = null; if (primarySelection != null) { controlForComponent = ((IOleDragClient) this).GetControlForComponent(primarySelection); } if ((controlForComponent != null) && (controlForComponent.Site == null)) { controlForComponent = null; } if ((primarySelection == base.Component) || (controlForComponent == null)) { dragRect.X = this.DefaultControlLocation.X; dragRect.Y = this.DefaultControlLocation.Y; } else { dragRect.X = controlForComponent.Location.X + this.GridSize.Width; dragRect.Y = controlForComponent.Location.Y + this.GridSize.Height; } } if (flag2) { dragRect.Width = size.Width; dragRect.Height = size.Height; } else { dragRect.Size = this.GetDefaultSize(newChild); } if (!flag2 && !flag) { Rectangle adjustedSnapLocation = this.GetAdjustedSnapLocation(Rectangle.Empty, dragRect); dragRect = this.GetControlStackLocation(adjustedSnapLocation); } else { dragRect = this.GetAdjustedSnapLocation(Rectangle.Empty, dragRect); } dragRect.X += size2.Width; dragRect.Y += size2.Height; if ((defaultValues != null) && defaultValues.Contains("ToolboxSnapDragDropEventArgs")) { ToolboxSnapDragDropEventArgs e = defaultValues["ToolboxSnapDragDropEventArgs"] as ToolboxSnapDragDropEventArgs; Rectangle rectangle3 = DesignerUtils.GetBoundsFromToolboxSnapDragDropInfo(e, dragRect, this.Control.IsMirrored); Control rootComponent = host.RootComponent as Control; if ((rootComponent != null) && rectangle3.IntersectsWith(rootComponent.ClientRectangle)) { dragRect = rectangle3; } } PropertyDescriptor member = TypeDescriptor.GetProperties(this.Control)["Controls"]; if (this.componentChangeSvc != null) { this.componentChangeSvc.OnComponentChanging(this.Control, member); } this.AddChildControl(newChild); PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(newChild); if (properties != null) { PropertyDescriptor descriptor2 = properties["Size"]; if (descriptor2 != null) { descriptor2.SetValue(newChild, new Size(dragRect.Width, dragRect.Height)); } Point point2 = new Point(dragRect.X, dragRect.Y); ScrollableControl parent = newChild.Parent as ScrollableControl; if (parent != null) { Point autoScrollPosition = parent.AutoScrollPosition; point2.Offset(-autoScrollPosition.X, -autoScrollPosition.Y); } descriptor2 = properties["Location"]; if (descriptor2 != null) { descriptor2.SetValue(newChild, point2); } } if (this.componentChangeSvc != null) { this.componentChangeSvc.OnComponentChanged(this.Control, member, this.Control.Controls, this.Control.Controls); } newChild.Update(); } }
/// <summary> /// Capture a specific control in the client area of a form. /// </summary> /// <param name="window">This is a control which should be captured.</param> /// <returns>The image which has been captured.</returns> public virtual Bitmap CaptureControl(Control window) { Rectangle rc = window.RectangleToScreen(window.DisplayRectangle); window.Update(); return capture(window, rc); }
private void ForceRefresh(Control c) { c.Invalidate(); c.Update(); c.Refresh(); }
private void SetPictureBoxColor(Control pbox, Color col) { if (pbox.InvokeRequired) { SetPictureBoxColorCallback d = new SetPictureBoxColorCallback(SetPictureBoxColor); this.Invoke(d, new object[] { pbox, col }); } else { pbox.BackColor = col; //proximityStateLbl.Text = col.ToString(); pbox.Update(); } }
/// <summary> /// Tries to invoke the RecalcLayout method on the control and return true if such method was invoked. /// </summary> /// <param name="c">Reference to the control</param> /// <param name="invalidate">Indicates whether to invalidate control if no recalc layout method is found</param> /// <returns>return true if method is invoked.</returns> public static bool InvokeRecalcLayout(Control c, bool invalidate) { if (c is ItemControl) { ((ItemControl)c).RecalcLayout(); return true; } else if (c is Bar) { ((Bar)c).RecalcLayout(); return true; } else if (c is ExplorerBar) { ((ExplorerBar)c).RecalcLayout(); return true; } else if (c is BaseItemControl) { ((BaseItemControl)c).RecalcLayout(); return true; } else if (c is BarBaseControl) { ((BarBaseControl)c).RecalcLayout(); return true; } else if (c is PopupItemControl) { ((PopupItemControl)c).RecalcLayout(); return true; } MethodInfo m = c.GetType().GetMethod("RecalcLayout"); if (m != null) { m.Invoke(c, null); return true; } else if (invalidate) { c.Invalidate(true); c.Update(); } return false; }
/// <summary> ///在指定的控件中添加用户控件。 /// </summary> /// <param name="parent"></param> /// <param name="userControl"></param> public virtual void AddUseControls(Control parent, IWindow userControl) { if (parent != null && userControl != null) { UserControl uc = userControl as UserControl; if (uc != null) { uc.AutoSize = true; if (uc.Dock == DockStyle.Fill) parent.Controls.Clear(); parent.Controls.Add(uc); parent.Update(); userControl.MessageEvent += this.OnMessageEvent; userControl.ToolTipEvent += this.OnToolTipEvent; userControl.SetErrorEvent += this.OnSetErrorEvent; userControl.ClearErrorEvent += this.OnClearErrorEvent; } } }