本文整理汇总了C#中System.Windows.Forms.Control.Invalidate方法的典型用法代码示例。如果您正苦于以下问题:C# Control.Invalidate方法的具体用法?C# Control.Invalidate怎么用?C# Control.Invalidate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.Invalidate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseBox
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();
};
}
示例2: Update
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;
}
}
}
示例3: BeginDrag
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;
}
示例4: BlinkControl
public BlinkControl(Control control, Color blinkColor, int blinkInterval)
{
_bcd = new BlinkControlDetails(control.BackColor, blinkColor);
_control = control;
_control.BackColor = blinkColor;
_control.Invalidate();
_timer.Interval = blinkInterval;
}
示例5: Resume
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);
}
示例6: TextureRenderer
public TextureRenderer(Control parentControl, GraphicsDevice graphicsDevice)
{
_parentControl = parentControl;
_spriteBatch = new SpriteBatch(graphicsDevice);
_fitToWindow = true;
Resize();
parentControl.Resize += (sender, e) =>
{
Resize();
_parentControl.Invalidate();
};
}
示例7: RefreshControl
//***************************************************************************
// 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();
}
示例8: SetControlDirection
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();
}
示例9: HandleMouseDown
/// <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();
}
}
示例10: TestPublicMethods
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");
//.........这里部分代码省略.........
示例11: Apply
//.........这里部分代码省略.........
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();
}
示例12: SelectWord
/// <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();
}
}
}
示例13: UpdateControl
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();
}
示例14: UpdateImage
/*
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));
//.........这里部分代码省略.........
示例15: DrawPipe
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);
}