本文整理汇总了C#中System.Windows.Forms.TextBox.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.Invoke方法的具体用法?C# TextBox.Invoke怎么用?C# TextBox.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TextBox
的用法示例。
在下文中一共展示了TextBox.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartAnomalyDetection
public static void StartAnomalyDetection(TextBox warningTextBox)
{
if (DoneSettingNormalUsage)
{
if (CPUMonitor.CPUCounter > NormalCPU)
{
if (warningTextBox.Text.Length == 0)
{
warningTextBox.Invoke(new Action(() =>
{
warningTextBox.Text = "CPU Usage: " + CPUMonitor.CPUCounter.ToString("F2") + "%";
CPUMonitor.CPUWarnings = warningTextBox.Text;
}));
}
else
{
warningTextBox.Invoke(new Action(() =>
{
warningTextBox.AppendText("\r\nCPU Usage: " + CPUMonitor.CPUCounter.ToString("F2") + "%");
CPUMonitor.CPUWarnings = warningTextBox.Text;
}));
}
}
}
}
示例2: CreateMessage
public static void CreateMessage(TextBox box, string msg, bool timer = true, bool appendText = true)
{
//set timer string depending on parameter
string timerLinespacing = " ";
string theTime;
string newline = "\r\n";
if (timer) { theTime = DateTime.Now.ToString("HH:mm:ss tt"); }
else { theTime = ""; }
if (appendText)
{
if (box.InvokeRequired)
{
box.Invoke(new MethodInvoker(delegate { box.Text += theTime + timerLinespacing + msg + newline; }));
}
else
{
box.Text += theTime + timerLinespacing + msg + newline;
}
}
else
{
if (box.InvokeRequired)
{
box.Invoke(new MethodInvoker(delegate { box.Text = msg + newline; }));
}
else
{
box.Text = msg + newline;
}
}
}
示例3: updateRegisterState
private void updateRegisterState(TextBox txt, Register register)
{
txt.Invoke((MethodInvoker)(() =>
{
txt.Text = _vm.cpu.Registers[register].ToString();
}));
}
示例4: SetTextBoxSafe
/// <summary>
/// Sets textbox text
/// </summary>
/// <param name="tb"></param>
/// <param name="text"></param>
private static void SetTextBoxSafe(TextBox tb, string text)
{
if (tb.InvokeRequired)
tb.Invoke(new Action(() => tb.Text = text));
else
tb.Text = text;
}
示例5: ProcessMonitoring
public static async void ProcessMonitoring(TextBox usageTextBox, TextBox listTextBox)
{
int changed = ProcessCounter;
string[] data;
while (true)
{
await Task.Delay(1000);
CurrentNumberProcesses();
usageTextBox.Invoke(new Action(() =>
{
usageTextBox.Text = ProcessCounter + "";
}));
if (changed != ProcessCounter)
{
changed = ProcessCounter;
listTextBox.Invoke(new Action(() =>
{
data = ReadProcesses();
foreach (string pData in data)
{
if (listTextBox.Text.Length < 0)
listTextBox.Text = pData;
else
listTextBox.AppendText($"\r\n{pData}");
}
}));
}
}
}
示例6: CPUMonitoring
//Function will read and display current CPU usage
public static async void CPUMonitoring(TextBox usageTextBox, TextBox warningTextBox)
{
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
while (true)
{
//First value always returns a 0
var unused = cpuCounter.NextValue();
await Task.Delay(1000);
usageTextBox.Invoke(new Action(() =>
{
CPUCounter = cpuCounter.NextValue();
usageTextBox.Text = CPUCounter.ToString("F2") + "%";
}));
CPUCalculations();
CPUAnomalies.StartAnomalyDetection(warningTextBox);
if (mainMenu.done)
break;
}
}
示例7: Main
static void Main()
{
var form = new Form { Width = 800, Height = 600};
textBox = new TextBox() { Dock = DockStyle.Fill, Multiline = true, Text = "Interact with the mouse or the keyboard...\r\n", ReadOnly = true};
form.Controls.Add(textBox);
form.Visible = true;
// setup the device
Device.RegisterDevice(UsagePage.Generic, UsageId.GenericMouse, DeviceFlags.None);
Device.MouseInput += (sender, args) => textBox.Invoke(new UpdateTextCallback(UpdateMouseText), args);
Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, DeviceFlags.None);
Device.KeyboardInput += (sender, args) => textBox.Invoke(new UpdateTextCallback(UpdateKeyboardText), args);
Application.Run(form);
}
示例8: add_text
public static void add_text(TextBox tb, object s)
{
if (tb.InvokeRequired)
tb.Invoke(new Action<TextBox, object>(add_text), new object[] { tb, s });
else
{
tb.AppendText(s.ToString());
tb.ScrollToCaret();
}
}
示例9: GetTextBoxText
private string GetTextBoxText(TextBox textbox)
{
string returnValue = null;
if (textbox.InvokeRequired)
textbox.Invoke((MethodInvoker)
delegate { returnValue = GetTextBoxText(textbox); });
else
return textbox.Text;
return returnValue;
}
示例10: showdata
public void showdata(string mac, string ip, float nhietdo, float doam, float nguon, TextBox text)
{
text.Invoke(new EventHandler(delegate
{
if (index == 2)
{
text.Text = "Sensor " + ip + "(" + mac + ")\r\nNhiet do : " + nhietdo + "\r\nDo am : " + doam + "\r\nNang luong : " + nguon;
mypanel.Show();
}
}));
}
示例11: UpdateUI
private void UpdateUI(TextBox tb, int data)
{
if (textBox1.InvokeRequired)
{
tb.Invoke(new UpdateStatus(UpdateUI), new object[] {tb, data });
}
else
{
tb.Text += data + Resources.TextSeparator;
}
}
示例12: updateTextBox
public static void updateTextBox(string strText, TextBox tbToUse)
{
if (tbToUse.InvokeRequired)
{
updateTextBoxCallback utbCallback = new updateTextBoxCallback(updateTextBox);
tbToUse.Invoke(utbCallback, new object[] { strText, tbToUse });
}
else
{
tbToUse.Text = strText + Environment.NewLine + tbToUse.Text;
}
}
示例13: SetTextBoxValue
private void SetTextBoxValue(string value, TextBox ctr)
{
Action<string> setValueAction = text => ctr.AppendText(value);//Action<T>本身就是delegate类型,省掉了delegate的定义
if (ctr.InvokeRequired)
{
ctr.Invoke(setValueAction, value);
}
else
{
setValueAction(value);
}
}
示例14: GetTextBoxText
public static string GetTextBoxText(TextBox box)
{
if (box.InvokeRequired)
{
Func<TextBox, string> deleg = new Func<TextBox, string>(GetTextBoxText);
return box.Invoke(deleg, new object[] { box }).ToString();
}
else
{
return box.Text;
}
}
示例15: PrintText
public void PrintText(TextBox textbox, string text)
{
if (textbox.InvokeRequired)
{
textbox.Invoke(new PrintTextCallback(PrintText), textbox, text);
}
else
{
textbox.Text += text;
textbox.SelectionStart = textbox.Text.Length;
textbox.ScrollToCaret();
}
}