public CloseBox(Control host) { this.host = host; host.Resize += delegate { host.Invalidate(); }; host.MouseLeave += delegate { hover = false; host.Invalidate(); }; host.MouseMove += delegate(object sender, MouseEventArgs e) { bool h = bounds.Contains(e.Location); if (hover != h) { hover = h; host.Invalidate(); } }; host.MouseUp += delegate(object sender, MouseEventArgs e) { if (bounds.Contains(e.Location) && e.Button == MouseButtons.Left) Clicked(); }; }
public void Invalidate( ) { if (parent_ != null) { parent_.Invalidate( ); } }
public void Update(Control parent) { bool inCdState = InCD; if (inCdState || LastInCD) { parent.Invalidate(new Rectangle(X + 6, Y + 50, 60, 20)); if (LastInCD != inCdState) { parent.Invalidate(new Rectangle(X, Y, Width, 50)); LastInCD = inCdState; } } }
} //public bool HandleMouseDown() public void UpdateView() { if (myOwnerControl != null) { myOwnerControl.Invalidate(new System.Drawing.Rectangle(intLeft, intTop, ItemSize * 2, ItemSize * 2)); } }
private static bool m_IsSimpleDrag = false; // Is this a simple drag? #endregion Fields #region Methods /// <summary> /// Returns the DataObject needed for a DoDragDrop, from a specified Control /// Used with controls that implement IDragDropEnabled (recommended usage) /// </summary> /// <param name="_ctrl">Control to get DataObject for</param> /// <param name="_invalidate">Invalidate the control or not? /// (Set to true if you need to change the appearance of the control during a DragDrop)</param> /// <returns>Control converted to a DataObject ready for dragging</returns> public static DataObject BeginDrag(Control _ctrl, bool _invalidate) { // If not initialized then throw an Exception if (!m_Initialized) throw new Exception(string.Format("{0} not initialized.", "EIBFormDesigner.Event.DragDropHandler"), null); // If this is not a valid control to be dragged, throw an exception if (!(_ctrl is IDragDropEnabled)) throw new ControlInterfaceException( string.Format("[{0}] only accepts controls that implement\n[{1}] for drag operations.\n\nUse {2} instead.", "EIBFormDesigner.Event", "IDragDropEnabled", "BeginSimpleDrag")); DataObject doControlToDrag = StoreControl(_ctrl, false); // Inform the control that it has begun a drag operation ((IDragDropEnabled)_ctrl).StoreLocation(); ((IDragDropEnabled)_ctrl).IsDragging = true; // Set the control up to be in the foreground and invalidate it // incase it needs redrawing if (_invalidate) { _ctrl.BringToFront(); _ctrl.Invalidate(); } // return the converted control as a DataObject return doControlToDrag; }
private void EnsureDestroyed() { if (_timer is not null) { _timer.Dispose(); _timer = null; } if (_tipWindow is not null) { _tipWindow.DestroyHandle(); _tipWindow = null; } // Hide the window and invalidate the parent to ensure // that we leave no visual artifacts. given that we // have a bizarre region window, this is needed. User32.SetWindowPos( new HandleRef(this, Handle), User32.HWND_TOP, _windowBounds.X, _windowBounds.Y, _windowBounds.Width, _windowBounds.Height, User32.SWP.HIDEWINDOW | User32.SWP.NOSIZE | User32.SWP.NOMOVE); _parent?.Invalidate(true); DestroyHandle(); }
public static void DrawAnimation(this System.Windows.Forms.Control control, Func <Boolean> doEffect, Int32 interval = 10) { Action action = () => { Timer effectTimer = new Timer(); effectTimer.Interval = interval; effectTimer.Tick += (s, e) => { Timer timer = s as Timer; timer.Enabled = false; try { if (doEffect != null && doEffect()) { control.Invalidate(); timer.Enabled = true; } else { timer.Dispose(); } } catch { timer.Dispose(); } }; }; control.Invoke(action); }
void PauseForDrama(int ms) // for debugging purposes { return; game.CurrentLevel.World.AddVec(game.CurrentLevel.Ball.Trajectory(), Color.Red); System.Threading.Thread.Sleep(ms); Render(false); targetControl.Invalidate(); }
public BlinkControl(Control control, Color blinkColor, int blinkInterval) { _bcd = new BlinkControlDetails(control.BackColor, blinkColor); _control = control; _control.BackColor = blinkColor; _control.Invalidate(); _timer.Interval = blinkInterval; }
public static void Resume(Control control) { // Create a C "true" boolean as an IntPtr IntPtr wparam = new IntPtr(1); Message msgResumeUpdate = Message.Create(control.Handle, WM_SETREDRAW, wparam, IntPtr.Zero); NativeWindow window = NativeWindow.FromHandle(control.Handle); window.DefWndProc(ref msgResumeUpdate); control.Invalidate(true); }
public virtual void Refresh() { if (Owner != null) { if (!Owner.IsDisposed) { if (Right == Left) { Owner.Invalidate(new System.Drawing.Rectangle(Left - 4, Top - 3, 8, Bottom - Top + 6)); } else if (Bottom == Top) { Owner.Invalidate(new System.Drawing.Rectangle(Left - 3, Top - 4, Right - Left + 6, 8)); } else { Owner.Invalidate(new System.Drawing.Rectangle(Left - 4, Top - 4, Right - Left + 8, Bottom - Top + 8)); } } } }
//*************************************************************************** // Static Methods // /// <summary> /// Tells the specified control to invalidate its client area and immediately redraw itself. /// </summary> /// <param name="ctrl"></param> public static void RefreshControl(Control ctrl) { if (ctrl.InvokeRequired) { RefreshControlDelegate del = new RefreshControlDelegate(CrossThreadUI.RefreshControl); if (CrossThreadUI.ExecSync) ctrl.Invoke(del); else ctrl.BeginInvoke(del); } else ctrl.Invalidate(); }
public TextureRenderer(Control parentControl, GraphicsDevice graphicsDevice) { _parentControl = parentControl; _spriteBatch = new SpriteBatch(graphicsDevice); _fitToWindow = true; Resize(); parentControl.Resize += (sender, e) => { Resize(); _parentControl.Invalidate(); }; }
public static void SetControlDirection(Control c, bool p_isRTL) { int style = GetWindowLong(c.Handle, GWL_EXSTYLE); style = GetWindowLong(c.Handle, GWL_STYLE); // set default to ltr (clear rtl bit) //style &= ~WS_EX_LAYOUTRTL; style &= ~ES_LEFT; if (p_isRTL == true) { // rtl //style = WS_EX_LAYOUTRTL; style = ES_RIGHT; } //SetWindowLong(c.Handle, GWL_EXSTYLE, style); SetWindowLong(c.Handle, GWL_STYLE, style); c.Invalidate(); }
/// <summary> /// 使得控件做一些动画效果 /// </summary> /// <param name="doEffect">实现动画效果的函数,当此函数返回false时动画效果触发停止</param> /// <param name="interval">动画帧触发间隔</param> public static void DoAnimation(this System.Windows.Forms.Control control, Func <Boolean> doEffect, Int32 interval = 55) { if (doEffect == null) { return; } Action action = () => { System.Windows.Forms.Timer effectTimer = new System.Windows.Forms.Timer(); Int32 mutex = 0; effectTimer.Interval = interval; effectTimer.Tick += (s, e) => { if (0 == mutex) { Interlocked.Exchange(ref mutex, 1); try { if (doEffect()) { control.Invalidate(); } else { effectTimer.Enabled = false; } } catch { effectTimer.Enabled = false; } Interlocked.Exchange(ref mutex, 0); } }; effectTimer.Start(); }; control.Invoke(action); }
/// <summary> /// Select the word at the given location if found. /// </summary> /// <param name="control">the control hosting the html to invalidate</param> /// <param name="loc">the location to select word at</param> public void SelectWord(Control control, Point loc) { if (_root.HtmlContainer.IsSelectionEnabled) { var word = DomUtils.GetCssBoxWord(_root, loc); if (word != null) { word.Selection = this; _selectionStartPoint = loc; _selectionStart = _selectionEnd = word; control.Invalidate(); } } }
/// <summary> /// Select all the words in the html. /// </summary> /// <param name="control">the control hosting the html to invalidate</param> public void SelectAll(Control control) { if (_root.HtmlContainer.IsSelectionEnabled) { ClearSelection(); SelectAllWords(_root); control.Invalidate(); } }
/// <summary> /// Handle mouse up to handle selection and link click. /// </summary> /// <param name="parent">the control hosting the html to invalidate</param> /// <param name="button">the mouse button that has been released</param> /// <returns>is the mouse up should be ignored</returns> public bool HandleMouseUp(Control parent, MouseButtons button) { bool ignore = false; if (_root.HtmlContainer.IsSelectionEnabled) { ignore = _inSelection; if (!_inSelection && (button & MouseButtons.Left) != 0 && _mouseDownOnSelectedWord) { ClearSelection(); parent.Invalidate(); } _mouseDownOnSelectedWord = false; _inSelection = false; } ignore = ignore || (DateTime.Now - _lastMouseDown > TimeSpan.FromSeconds(1)); return ignore; }
/// <summary> /// Handle mouse down to handle selection. /// </summary> /// <param name="parent">the control hosting the html to invalidate</param> /// <param name="loc">the location of the mouse on the html</param> /// <param name="isMouseInContainer"> </param> public void HandleMouseDown(Control parent, Point loc, bool isMouseInContainer) { bool clear = !isMouseInContainer; if(isMouseInContainer) { _isDoubleClickSelect = (DateTime.Now - _lastMouseDown).TotalMilliseconds < 400; _lastMouseDown = DateTime.Now; _mouseDownOnSelectedWord = false; if (_root.HtmlContainer.IsSelectionEnabled && (Control.MouseButtons & MouseButtons.Left) != 0) { var word = DomUtils.GetCssBoxWord(_root, loc); if (word != null && word.Selected) { _mouseDownOnSelectedWord = true; } else { clear = true; } } else if ((Control.MouseButtons & MouseButtons.Right) != 0) { var rect = DomUtils.GetCssBoxWord(_root, loc); var link = DomUtils.GetLinkBox(_root, loc); if(_root.HtmlContainer.IsContextMenuEnabled) { _contextMenuHandler.ShowContextMenu(parent, rect, link); } clear = rect == null || !rect.Selected; } } if (clear) { ClearSelection(); parent.Invalidate(); } }
private void HandleResize(object sender, EventArgs e) { Control ctrl = (Control)sender; ctrl.Invalidate(last_painted_area); }
/* public override void UpdateImage(object sender, Image image) { Control c = (Control)sender; Graphics gImg = Graphics.FromImage(image); gImg.DrawLine(pen, ptStart.X, ptStart.Y, ptEnd.X, ptEnd.Y); gImg.Dispose(); c.Invalidate(); } */ protected void FillFlood(Control c, Point node, Image image) { Color target_color = Color.Empty; Color color_of_node = Color.Empty; Color replacement_color = Color.Empty; Bitmap tmpBmp = new Bitmap(image); //Set Q to the empty queue System.Collections.Queue q = new System.Collections.Queue(); //replacement_color is opposite color of node try { target_color = tmpBmp.GetPixel(node.X, node.Y); replacement_color = Color.FromArgb(Byte.MaxValue - target_color.R, Byte.MaxValue - target_color.G, Byte.MaxValue - target_color.B); } catch (ArgumentOutOfRangeException aore) { return; } //Add node to the end of Q q.Enqueue(node); Graphics gBmp = Graphics.FromImage(image); Graphics gTmp = Graphics.FromImage(tmpBmp); Pen aPen = new Pen(replacement_color, 1); //For each element n of Q while (q.Count > 0) { Point n = (Point)q.Dequeue(); //If the color of n is not equal to target_color, skip this iteration. try { color_of_node = tmpBmp.GetPixel(n.X, n.Y); if (color_of_node.Equals(target_color) == false) { continue; } } catch (ArgumentOutOfRangeException aore) { continue; } //Set w and e equal to n. Point w = n; Point e = n; //Move w to the west until the color of the node w no longer matches target_color. Color west_node_color = Color.Empty; do { try { west_node_color = tmpBmp.GetPixel(--w.X, w.Y); } catch (ArgumentOutOfRangeException aore) { w.X++; break; } } while (west_node_color.Equals(target_color)); //Move e to the east until the color of the node e no longer matches target_color. Color east_node_color = Color.Empty; do { try { east_node_color = tmpBmp.GetPixel(++e.X, e.Y); } catch (ArgumentOutOfRangeException aore) { e.X--; break; } } while (east_node_color.Equals(target_color)); //Set the color of node s between w and e to replacement_color gBmp.DrawLine(pen, w, e); gTmp.DrawLine(aPen, w, e); c.Invalidate(new Rectangle(w.X, w.Y, e.X - w.X, 1)); //For each node n2 between w and e. int y = w.Y - 1; bool isLine = false; for (int x = w.X; x <= e.X; x++) { //If the color of node at the north of n is target_color, add that node to the end of Q. try { Color test = tmpBmp.GetPixel(x, y); if (tmpBmp.GetPixel(x, y).Equals(target_color)) { if (isLine == false) { q.Enqueue(new Point(x, y)); isLine = true; } } else { isLine = false; } } catch (ArgumentOutOfRangeException aore) { break; } } y = w.Y + 1; isLine = false; for (int x = w.X; x <= e.X; x++) { //If the color of node at the north of n is target_color, add that node to the end of Q. try { if (tmpBmp.GetPixel(x, y).Equals(target_color)) { if (isLine == false) { q.Enqueue(new Point(x, y)); isLine = true; } } else { isLine = false; } } catch (ArgumentOutOfRangeException aore) { break; } } }/* while */ aPen.Dispose(); gBmp.Dispose(); gTmp.Dispose(); }
public static void ResumeDrawing(Control parent) { SendMessage(parent.Handle, WM_SETREDRAW, true, 0); parent.Invalidate(); parent.Refresh(); }
//Deserialize individual base windows and there child control public static void DeserializeWindowXML(string fileName, Control baseFrame, XmlNode parentXMLNode) { DataSet dataset = new DataSet(); XmlDocument doc = new XmlDocument(); XmlNode currentXmlNode = null; Dictionary<string, EIBNode> listNode = new Dictionary<string, EIBNode>(); try { // disabling re-drawing of treeview till all nodes are added baseFrame.SuspendLayout(); fileName = fileName + ".xml"; if (parentXMLNode == null) { doc.Load(fileName); currentXmlNode = doc.FirstChild; } else { currentXmlNode = parentXMLNode; } baseFrame.Controls.Clear(); if (currentXmlNode.Name == FormDesignerConstants.BaseWindow) { // loading node attributes UpdateControlProperties(baseFrame, currentXmlNode); } //Iterate all nodes foreach (XmlNode xmlNode in currentXmlNode.ChildNodes) { if (xmlNode.NodeType == XmlNodeType.Element) { if (xmlNode.Name == FormDesignerConstants.NodeControl) { EIBNode.counter++; EIBNode eibNode = new EIBNode(); UpdateControlProperties(eibNode, xmlNode); eibNode.nodeIdText.Text = xmlNode.Attributes["id"].Value.ToString(); eibNode.startNodeCheck.Checked = (xmlNode.Attributes["isstart"].Value.ToLower().Equals("true")); // baseFrame.Controls.Add(eibNode); listNode.Add(eibNode.nodeIdText.Text, eibNode); //EIBNode newNode = new EIBNode(); // UpdateControlProperties(newNode, xmlNode); // newNode.nodeIdText.Text = xmlNode["workflownode"].Attributes["id"].Value.ToString(); // newNode.startNodeCheck.Checked = (xmlNode["workflownode"].Attributes["isstart"].Value.ToLower().Equals("true")); //XmlNode xmlWorkFlowNode = getXMLNodeWithName(xmlNode,"workflownode") //xmlNode[ eibNode.WorkFlowNode= Desearializeworkflownodexml(xmlNode); eibNode.workflowNode.WorkFlowNodeId = eibNode.nodeIdText.Text; eibNode.nodeIdText.Enabled = false; ((BaseWindow)baseFrame.Parent).WorkflowNodes.Add(eibNode.workflowNode.WorkFlowNodeId, eibNode); baseFrame.Controls.Add(eibNode); } if (xmlNode.Name == "connector") { try { //EIBNodeConnector.counter++; EIBNodeConnector newNode = new EIBNodeConnector(); XmlNode xmlNodeconnector = xmlNode; UpdateControlProperties(newNode, xmlNodeconnector); XmlNode connectorNode = xmlNodeconnector; //XmlNode fromNodeName = connectorNode["from"].Attributes["id"]; //XmlNode toNodeName = connectorNode["to"].Attributes["id"]; string fromNodeName = connectorNode["from"].Attributes["id"].Value; string toNodeName = connectorNode["to"].Attributes["id"].Value; EIBNode fromNode = listNode[fromNodeName]; EIBNode toNode = listNode[toNodeName]; Graphics g = null; Bitmap bmpBack = new Bitmap(baseFrame.Width, baseFrame.Height); Graphics.FromImage(bmpBack).Clear(baseFrame.BackColor); baseFrame.BackgroundImage = (Bitmap)bmpBack.Clone(); g = Graphics.FromImage(baseFrame.BackgroundImage); int centerMarkX = (fromNode.Center.X + toNode.Center.X) / 2; int centerMarkY = (fromNode.Center.Y + toNode.Center.Y) / 2; newNode.centerMark.Location = new Point(centerMarkX - 4, centerMarkY - 4); newNode.InitiateSettings((EIBPanel)baseFrame); newNode.Mark1 = fromNode; newNode.Mark2 = toNode; newNode.createLine(); baseFrame.Controls.Add(newNode.centerMark); g.DrawLine(new Pen(Color.RoyalBlue, (float)2), fromNode.Center.X, fromNode.Center.Y, centerMarkX, centerMarkY); g.DrawLine(new Pen(Color.RoyalBlue, (float)2), toNode.Center.X, toNode.Center.Y, centerMarkX, centerMarkY); baseFrame.Controls.Add(newNode); } catch (Exception ex) { MessageBox.Show("Connector xml Modified."); } } } } //Iterate all nodes connector /*foreach (XmlNode xmlNodeconnector in currentXmlNode.ChildNodes) { if (xmlNodeconnector.NodeType == XmlNodeType.Element) { } }*/ } catch (FileNotFoundException) { MessageBox.Show("Basewindow.xml not Found"); } finally { baseFrame.ResumeLayout(); // enabling redrawing of treeview after all nodes are added baseFrame.Invalidate(); } }
public DelayedLayout(Control control) { this.control = control; control.Paint += this.OnLoaded; control.Invalidate(); }
private void ForceRefresh(Control c) { c.Invalidate(); c.Update(); c.Refresh(); }
private void InvalidateCtrl(Control ctl) { if (this.InvokeRequired) { this.Invoke(new InvalidateDelegate(InvalidateCtrl), new Object[] { ctl }); } else { ctl.Invalidate(); } }
private void UpdateControl(Control controlToUpdate, Color newBackColor) { if (controlToUpdate == null) return; if (controlToUpdate.ContextMenuStrip != null) { UpdateToolStrip(controlToUpdate.ContextMenuStrip, newBackColor); } var tabControl = controlToUpdate as MaterialTabControl; if (tabControl != null) { foreach (TabPage tabPage in tabControl.TabPages) { tabPage.BackColor = newBackColor; } } if (controlToUpdate is MaterialDivider) { controlToUpdate.BackColor = GetDividersColor(); } if (controlToUpdate is MaterialListView) { controlToUpdate.BackColor = newBackColor; } //recursive call foreach (Control control in controlToUpdate.Controls) { UpdateControl(control, newBackColor); } controlToUpdate.Invalidate(); }
/// <summary> /// Handle html text selection by mouse move over the html with left mouse button pressed.<br/> /// Calculate the words in the selected range and set their selected property. /// </summary> /// <param name="control">the control hosting the html to invalidate</param> /// <param name="loc">the mouse location</param> /// <param name="allowPartialSelect">true - partial word selection allowed, false - only full words selection</param> private void HandleSelection(Control control, Point loc, bool allowPartialSelect) { // get the line under the mouse or nearest from the top var lineBox = DomUtils.GetCssLineBox(_root, loc); if (lineBox != null) { // get the word under the mouse var word = DomUtils.GetCssBoxWord(lineBox, loc); // if no word found under the mouse use the last or the first word in the line if (word == null && lineBox.Words.Count > 0) { if (loc.Y > lineBox.LineBottom) { // under the line word = lineBox.Words[lineBox.Words.Count - 1]; } else if (loc.X < lineBox.Words[0].Left) { // before the line word = lineBox.Words[0]; } else if (loc.X > lineBox.Words[lineBox.Words.Count - 1].Right) { // at the end of the line word = lineBox.Words[lineBox.Words.Count - 1]; } } // if there is matching word if (word != null) { if (_selectionStart == null) { // on start set the selection start word _selectionStartPoint = loc; _selectionStart = word; if (allowPartialSelect) CalculateWordCharIndexAndOffset(control, word, loc, true); } // always set selection end word _selectionEnd = word; if (allowPartialSelect) CalculateWordCharIndexAndOffset(control, word, loc, false); ClearSelection(_root); if (CheckNonEmptySelection(loc, allowPartialSelect)) { CheckSelectionDirection(); SelectWordsInRange(_root, _backwardSelection ? _selectionEnd : _selectionStart, _backwardSelection ? _selectionStart : _selectionEnd); } else { _selectionEnd = null; } _cursorChanged = true; control.Cursor = Cursors.IBeam; control.Invalidate(); } } }
public static void CallControlInvalidate(Control c, object[] obj) { if(obj.Length == 1) { if(obj[0].GetType() == typeof(bool)) c.Invalidate((bool)obj[0]); else if(obj[0].GetType() == typeof(Rectangle)) c.Invalidate((Rectangle)obj[0]); else if(obj[0].GetType() == typeof(Region)) c.Invalidate((Region)obj[0]); } else if(obj.Length == 2) { if(obj[0].GetType() == typeof(Rectangle) && obj[1].GetType() == typeof(bool)) c.Invalidate((Rectangle)obj[0], (bool)obj[1]); else if(obj[0].GetType() == typeof(Region) && obj[1].GetType() == typeof(bool)) c.Invalidate((Region)obj[0], (bool)obj[1]); } }
public virtual void Apply(Control c) { c.Font = FontNormal; if (c is Skin.CheckBox) { Skin.CheckBox c2 = c as Skin.CheckBox; c2.BackColor = Color.Transparent; c2.ForeColor = ForeColor; if (GetStyle() == "flat") c2.FlatStyle = FlatStyle.Flat; else c2.FlatStyle = FlatStyle.Standard; } if (c is Skin.ComboBox) { Skin.ComboBox c2 = c as Skin.ComboBox; c2.BackColor = BackColor; c2.ForeColor = ForeColor; if (GetStyle() == "flat") c2.FlatStyle = FlatStyle.Flat; else c2.FlatStyle = FlatStyle.Standard; } if (c is Skin.TextBox) { Skin.TextBox c2 = c as Skin.TextBox; if(c2.ReadOnly) c2.BackColor = ReadOnlyBackColor; else c2.BackColor = BackColor; c2.ForeColor = ForeColor; if (GetStyle() == "flat") c2.BorderStyle = BorderStyle.FixedSingle; else c2.BorderStyle = BorderStyle.Fixed3D; } if (c is Skin.Label) { } if (c is Skin.RadioButton) { Skin.RadioButton c2 = c as Skin.RadioButton; c2.BackColor = Color.Transparent; c2.ForeColor = ForeColor; if (GetStyle() == "flat") c2.FlatStyle = FlatStyle.Flat; else c2.FlatStyle = FlatStyle.Standard; } if (c is Skin.LinkLabel) { Skin.LinkLabel c2 = c as Skin.LinkLabel; c2.BackColor = Color.Transparent; c2.ForeColor = HyperLinkForeColor; //c2.ActiveLinkColor = HyperLinkColor; //c2.LinkColor = HyperLinkColor; //c2.VisitedLinkColor = HyperLinkColor; } if (c is Skin.TabPage) { Skin.TabPage c2 = c as Skin.TabPage; c2.BackColor = Color.Transparent; } if (c is Skin.ListView) { Skin.ListView c2 = c as Skin.ListView; c2.BackColor = BackColor; c2.ForeColor = ForeColor; if (GetStyle() == "flat") c2.BorderStyle = BorderStyle.FixedSingle; else c2.BorderStyle = BorderStyle.Fixed3D; } if (c is Skin.Button) { Skin.Button c2 = c as Skin.Button; c2.ForeColor = ForeColor; //c2.UpdateBackground(); } foreach (Control sc in c.Controls) { Apply(sc); } c.Invalidate(); }
protected override void Invalidate(Control containerControl) { if (this.DesignMode) { if (containerControl.InvokeRequired) containerControl.BeginInvoke(new MethodInvoker(delegate { containerControl.Invalidate(); })); else containerControl.Invalidate(); } else { if (containerControl.InvokeRequired) containerControl.BeginInvoke(new MethodInvoker(delegate { containerControl.Invalidate(m_Rect, true); })); else containerControl.Invalidate(m_Rect, true); } }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="control">the inner .NET Control for the widget</param> public ImageWidgetBase(Control control) : base(control) { IsHighlightOn = false; IsSelectedHighlightOn = false; if (control is PictureBox) { pictureBox = (PictureBox)control; } control.Invalidate(); }
public void DrawPipe(Graphics g, float width, Point p1, Point p2, Color mid_color, Color edge_color, Control c) { SizeF along = new SizeF(p2.X - p1.X, p2.Y - p1.Y); float mag = (float)Math.Sqrt(along.Width * along.Width + along.Height * along.Height); along = new SizeF(along.Width / mag, along.Height / mag); SizeF perp = new SizeF(-along.Height, along.Width); PointF p1L = new PointF(p1.X + width / 2 * perp.Width, p1.Y + width / 2 * perp.Height); PointF p1R = new PointF(p1.X - width / 2 * perp.Width, p1.Y - width / 2 * perp.Height); PointF p2L = new PointF(p2.X + width / 2 * perp.Width, p2.Y + width / 2 * perp.Height); PointF p2R = new PointF(p2.X - width / 2 * perp.Width, p2.Y - width / 2 * perp.Height); GraphicsPath gp = new GraphicsPath(); gp.AddEllipse(new Rectangle(p1.X - (int)width / 2, p1.Y - (int)width / 2, (int)width / 2 * 2, (int)width / 2 * 2)); gp.AddEllipse(new Rectangle(p2.X - (int)width / 2, p2.Y - (int)width / 2, (int)width / 2 * 2, (int)width / 2 * 2)); gp.AddLines(new PointF[] { p1, p1L, p2L, p2, p2R, p1R }); gp.CloseFigure(); Region region = new Region(gp); using (PathGradientBrush brush = new PathGradientBrush(gp)) { brush.CenterColor = mid_color; brush.SurroundColors = new Color[] { edge_color, mid_color, edge_color,edge_color,mid_color,edge_color,edge_color, edge_color }; g.FillRegion(brush, region); } c.Invalidate(region); }
// Update the sample region. private void UpdateSample() { sample.Invalidate(); }
public static void Invalidate(Control control) { if (control.InvokeRequired) { control.BeginInvoke(new Action(() => { control.Invalidate(); })); } else { control.Invalidate(); } }
//Deserialize individual base windows and there child control public static void DeserializeWindowXML(string fileName, Control baseFrame, XmlNode parentXMLNode) { DataSet dataset = new DataSet(); int nextTop = 0, nextLeft = 0; int maxHeight = 0, maxWidth = 0; int ParentWidth; Dictionary<string, EIBTable> listTable = new Dictionary<string, EIBTable>(); try { ParentWidth = baseFrame.Width; // disabling re-drawing of treeview till all nodes are added baseFrame.SuspendLayout(); fileName = fileName + ".xml"; string datasetName = System.IO.Path.GetFileNameWithoutExtension(fileName); List<string> M2MList = new List<string>(); dataset = DatabaseXMLServices.ReadSchema(datasetName, fileName,M2MList); //dataset.ReadXml(fileName); baseFrame.Controls.Clear(); ((BaseWindow)baseFrame.Parent).DatabaseDataSet = dataset; foreach (DataTable table in dataset.Tables) { EIBTable.counter++; EIBTable newNode = new EIBTable(); newNode.TableData = table; newNode.Height = 160; newNode.Width = 200; newNode.DatabaseDataSet = dataset; newNode.Name = table.TableName; listTable.Add(newNode.Name, newNode); newNode.ControlName = table.TableName; newNode.tableName.Text = table.TableName; if (M2MList.Contains(table.TableName)) { newNode.M2M = true; } else { newNode.M2M = false; } newNode.Top = nextTop; newNode.Left = nextLeft; UpdateControlProperties(newNode); newNode.AutoSize = false; baseFrame.Controls.Add(newNode); if (newNode.Height > maxHeight) { maxHeight = newNode.Height; } if (newNode.Width > maxWidth) { maxWidth = newNode.Width; } if ((nextLeft + newNode.Width + maxWidth) >= ParentWidth) { nextTop += maxHeight; nextLeft = 0; } else { nextLeft += newNode.Width; } foreach (DataColumn column in table.Columns) { ListViewItem lvItem = new ListViewItem(column.ColumnName); if (column.DataType.Name == typeof(string).Name) { int iCap; bool isVarChar = Int32.TryParse(column.Caption,out iCap); if (isVarChar) lvItem.SubItems.Add(column.DataType.Name); else lvItem.SubItems.Add(Designer.Database.DatabaseConstants.LongTextType); } else { lvItem.SubItems.Add(column.DataType.Name); } string autoIncrement = null; if (column.AutoIncrement) { autoIncrement = "Yes"; } else { autoIncrement = "No"; } lvItem.SubItems.Add(autoIncrement); string uniqueKey = null; if (column.Unique) { uniqueKey = "Yes"; } else { uniqueKey = "No"; } lvItem.SubItems.Add(uniqueKey); int iCaption; if (column.Caption != null && (!column.Caption.Trim().Equals("")) && Int32.TryParse(column.Caption,out iCaption)) { lvItem.SubItems.Add(column.Caption); } else { lvItem.SubItems.Add(""); } if (column.Unique) { lvItem.SubItems.Add("Not Null"); } else { lvItem.SubItems.Add((column.AllowDBNull ? "Null" : "Not Null")); } newNode.lvDatabase.Items.Add(lvItem); } } foreach (DataRelation relation in dataset.Relations) { EIBTableConnector tableConnector = new EIBTableConnector(); tableConnector.InitiateSettings((EIBPanel)baseFrame); tableConnector.Mark1 = (EIBTable)listTable[relation.ParentTable.TableName]; tableConnector.Mark2 = (EIBTable)listTable[relation.ChildTable.TableName]; tableConnector.createLine(); baseFrame.Controls.Add(tableConnector); } } catch (FileNotFoundException) { MessageBox.Show("Basewindow.xml not Found"); } catch (XmlException) { MessageBox.Show("DataPattern xml is changed."); } finally { // enabling redrawing of treeview after all nodes are added baseFrame.ResumeLayout(); baseFrame.Invalidate(); } }
/// <summary> /// 递归 Invalidate 一个 Control 和它的全部子 Control /// </summary> /// <param name="control">Control 对象</param> public static void InvalidateAllControls(Control control) { control.Invalidate(); for (int i = 0; i < control.Controls.Count; i++) { InvalidateAllControls(control.Controls[i]); // 递归 } }
protected virtual void Invalidate(Control containerControl) { if (this.DesignMode) { if (containerControl is Form && !(containerControl is RadialMenuPopup)) { if (IsHandleValid(containerControl)) InvalidateFormCaption(containerControl); containerControl.Refresh(); } else { if (containerControl.InvokeRequired) containerControl.BeginInvoke(new MethodInvoker(delegate { containerControl.Invalidate(); })); else containerControl.Invalidate(); } } else { if (containerControl is Form && !(containerControl is RadialMenuPopup)) { if (IsHandleValid(containerControl)) InvalidateFormCaption(containerControl); } else { if (containerControl.InvokeRequired) containerControl.BeginInvoke(new MethodInvoker(delegate { containerControl.Invalidate(GetInvalidateBounds(), true); })); else containerControl.Invalidate(GetInvalidateBounds(), true); } } }
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"); }
///<summary>Only used when blue theme is changed.</summary> private void RecursiveInvalidate(Control control){ foreach(Control c in control.Controls) { RecursiveInvalidate(c); } control.Invalidate(); }
/// <summary> /// Handles the MouseMove on the control /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Control_MouseMove(object sender, MouseEventArgs e) { if (IsSupsended || Disposed) { return; } HitTest(e.Location); #region Selected ones if (SelectedPanel != null && SelectedPanel != HittedPanel) { SelectedPanel.SetSelected(false); SelectedPanel.OnMouseLeave(e); Control.Invalidate(SelectedPanel.Bounds); } if (SelectedItem != null && SelectedItem != HittedItem) { SelectedItem.SetSelected(false); SelectedItem.OnMouseLeave(e); Control.Invalidate(SelectedItem.Bounds); } if (SelectedSubItem != null && SelectedSubItem != HittedSubItem) { SelectedSubItem.SetSelected(false); SelectedSubItem.OnMouseLeave(e); Control.Invalidate(Rectangle.Intersect(SelectedItem.Bounds, SelectedSubItem.Bounds)); } #endregion #region Tab Scrolls if (HittedTab != null) { if (HittedTab.ScrollLeftVisible) { HittedTab.SetScrollLeftSelected(HittedTabScrollLeft); Control.Invalidate(HittedTab.ScrollLeftBounds); } if (HittedTab.ScrollRightVisible) { HittedTab.SetScrollRightSelected(HittedTabScrollRight); Control.Invalidate(HittedTab.ScrollRightBounds); } } #endregion #region Panel if (HittedPanel != null) { if (HittedPanel == SelectedPanel) { HittedPanel.OnMouseMove(e); } else { HittedPanel.SetSelected(true); HittedPanel.OnMouseEnter(e); Control.Invalidate(HittedPanel.Bounds); } } #endregion #region Item if (HittedItem != null) { if (HittedItem == SelectedItem) { HittedItem.OnMouseMove(e); } else { HittedItem.SetSelected(true); HittedItem.OnMouseEnter(e); Control.Invalidate(HittedItem.Bounds); } } #endregion #region SubItem if (HittedSubItem != null) { if (HittedSubItem == SelectedSubItem) { HittedSubItem.OnMouseMove(e); } else { HittedSubItem.SetSelected(true); HittedSubItem.OnMouseEnter(e); Control.Invalidate(Rectangle.Intersect(HittedItem.Bounds, HittedSubItem.Bounds)); } } #endregion }