-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExeMethods.cs
89 lines (82 loc) · 2.76 KB
/
ExeMethods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ScoketTcp
{
public static class ExeMethods
{
/// <summary>
/// 定位到文本末
/// </summary>
/// <param name="textBox"></param>
public static void HoldBottom(this TextBox textBox)
{
//获取焦点
textBox.Focus();
//光标定位到文本后
textBox.Select(textBox.TextLength, 0);
//滚动到光标处
textBox.ScrollToCaret();
}
/// <summary>
/// 增加信息【跨线程】
/// </summary>
/// <param name="textBox"></param>
/// <param name="msg">要增加的消息</param>
/// <returns></returns>
public static object AddInfo(this TextBox textBox, string msg)
{
return textBox.Invoke(new Action<string>(m =>
{
textBox.AppendText($"[{DateTime.Now}]{Environment.NewLine}{m}{Environment.NewLine}{Environment.NewLine}");
textBox.HoldBottom();
}), msg);
}
/// <summary>
/// 刷新列表
/// </summary>
/// <param name="listBox"></param>
/// <param name="item">要操作的目标</param>
/// <param name="AddOrRme">操作 [Add:True] [Remove:False]</param>
/// <returns></returns>
public static object RefrshInfo(this ListBox listBox,string item,bool AddOrRme)
{
return listBox.Invoke(new Action<string, bool>((m, f) =>
{
if (f && !listBox.Items.Contains(m))
listBox.Items.Add(m);
else if (!f && listBox.Items.Contains(m))
listBox.Items.Remove(m);
}), item, AddOrRme);
}
/// <summary>
/// 以文件的形势发送
/// </summary>
/// <param name="srcArrByte"></param>
/// <returns></returns>
public static byte[] ToFile(this byte[] srcArrByte)
{
byte[] dtsArrByte = new byte[srcArrByte.Length + 1];
dtsArrByte[0] = 1;
Buffer.BlockCopy(srcArrByte, 0, dtsArrByte, 1, srcArrByte.Length);
return dtsArrByte;
}
/// <summary>
/// 以文本的形势发送
/// </summary>
/// <param name="srcArrByte"></param>
/// <returns></returns>
public static byte[] ToTxt(this byte[] srcArrByte)
{
byte[] dtsArrByte = new byte[srcArrByte.Length + 1];
dtsArrByte[0] = 0;
Buffer.BlockCopy(srcArrByte, 0, dtsArrByte, 1, srcArrByte.Length);
return dtsArrByte;
}
}
}