Beispiel #1
0
 /// <summary>
 /// 设置控件Text
 /// </summary>
 public void setObj(Control c, string obj, bool isAdd = false)
 {
     if (c.InvokeRequired)
     {
         // 解决窗体关闭时出现“访问已释放句柄”异常
         while (c.IsHandleCreated == false)
         {
             if (c.Disposing || c.IsDisposed)
             {
                 return;
             }
         }
         SetControlTextCallback d = new SetControlTextCallback(setObj);
         c.Invoke(d, new object[] { c, obj, isAdd });
     }
     else
     {
         if (!isAdd)
         {
             c.Text = obj;
         }
         else
         {
             c.Text += obj;
         }
     }
 }
 public void AppendControlTextValue(Control control, string text)
 {
     if (textBox1.InvokeRequired)
     {
         SetControlTextCallback d = new SetControlTextCallback(SetControlTextValue);
         Invoke(d, new object[] { control, text });
     }
     else
     {
         control.Text = text;
     }
 }
Beispiel #3
0
 private void SetControlTextThreadSafe(Control c, string s)
 {
     if (c.InvokeRequired)
     {
         var d = new SetControlTextCallback(SetControlTextThreadSafe);
         this.Invoke(d, new object[] { c, s });
     }
     else
     {
         c.Text = s;
     }
 }
Beispiel #4
0
 // Update the text on a control
 private void updateControlText(Control control, String text)
 {
     if (!control.IsDisposed)
     {
         if (control.InvokeRequired)
         {
             SetControlTextCallback update = new SetControlTextCallback(_updateControlText);
             control.Invoke(update, new object[] { control, text });
         }
         else
         {
             _updateControlText(control, text);
         }
     }
 }
 public void SetControlTextValue(Control control, string text)
 {
     //to remedy crossthreading errors while using selenium and Winforms
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (textBox1.InvokeRequired)
     {
         SetControlTextCallback d = new SetControlTextCallback(SetControlTextValue);
         Invoke(d, new object[] { control, text });
     }
     else
     {
         control.Text = text;
     }
 }
Beispiel #6
0
 public void SetControlText(Control control, string val)
 {
     if (control.InvokeRequired)
     {
         SetControlTextCallback d = SetControlText;
         try
         {
             Invoke(d, new object[] { control, val });
         }
         catch (Exception) { }
     }
     else
     {
         control.Text = val;
     }
 }
Beispiel #7
0
 /// <summary>
 /// Change the text label of a control
 /// </summary>
 /// <param name="container">The control that contains the control to change</param>
 /// <param name="control">The control to change</param>
 /// <param name="val">The new text</param>
 public static void SetControlText(Control container, Control control, string val)
 {
     if (container == null || control == null)
     {
         return;
     }
     if (container.InvokeRequired)
     {
         SetControlTextCallback d = SetControlText;
         try
         {
             container.Invoke(d, new object[] { container, control, val });
         }
         catch { }
     }
     else
     {
         control.Text = val;
     }
 }
Beispiel #8
0
 /// <summary>
 /// Change the text label of a control
 /// </summary>
 /// <param name="container">The control that contains the control to change</param>
 /// <param name="control">The control to change</param>
 /// <param name="val">The new text</param>
 public static void SetControlText(Control container, Control control, string val)
 {
     if (container == null || control == null)
     {
         return;
     }
     if (container.InvokeRequired)
     {
         SetControlTextCallback d = SetControlText;
         try
         {
             container.Invoke(d, new object[] { container, control, val });
         }
         catch { }
     }
     else
     {
         // I'm seeing InvokeRequired sometimes returning false and then failing here because invoke was required after all when running in the debugger
         // just ignore the issue when it happens. text will update a bit later anyway
         try { control.Text = val; }
         catch (InvalidOperationException) { }
     }
 }
Beispiel #9
0
 /// <summary>
 /// Thread safe method of setting text box text
 /// </summary>
 /// <param name="control">Control to set text for</param>
 /// <param name="text">Text to put into the control</param>
 protected void SetControlText(Control control, string text)
 {
    if (control.InvokeRequired)
    {
       SetControlTextCallback d = new SetControlTextCallback(SetControlText);
       Invoke(d, new object[] { control, text });
    }
    else
    {
       control.Text = text;
    }
 }            
Beispiel #10
0
 //
 // Functions to update forms, text boxes, labels and check boxes on the form either
 // directly or via callbacks since they may be called from the receive message
 // function which is in a different thread.
 //
 // Update the text on a control
 private void updateControlText(Control control, String text)
 {
     if (control.InvokeRequired)
     {
         SetControlTextCallback update = new SetControlTextCallback(_updateControlText);
         control.Invoke(update, new object[] { control, text });
     }
     else
     {
         _updateControlText(control, text);
     }
 }