📄 form1.cs
字号:
this.radioButton2.Location = new System.Drawing.Point(120, 24);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(104, 24);
this.radioButton2.TabIndex = 4;
this.radioButton2.Text = "恢复修改";
//
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(8, 24);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(104, 24);
this.radioButton1.TabIndex = 3;
this.radioButton1.Text = "修改注册表";
//
// button11
//
this.button11.Location = new System.Drawing.Point(168, 88);
this.button11.Name = "button11";
this.button11.Size = new System.Drawing.Size(75, 23);
this.button11.TabIndex = 2;
this.button11.Text = "查看记录";
this.button11.Click += new System.EventHandler(this.button11_Click);
//
// button10
//
this.button10.Location = new System.Drawing.Point(88, 88);
this.button10.Name = "button10";
this.button10.Size = new System.Drawing.Size(75, 23);
this.button10.TabIndex = 1;
this.button10.Text = "保存记录";
this.button10.Click += new System.EventHandler(this.button10_Click);
//
// button9
//
this.button9.Location = new System.Drawing.Point(8, 88);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(75, 23);
this.button9.TabIndex = 0;
this.button9.Text = "控制生效";
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// saveFileDialog1
//
this.saveFileDialog1.FileName = "doc1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(504, 317);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Friendly Controller";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
//"修改选项"button函数的功能,转向Form2的界面.
private void button3_Click(object sender, System.EventArgs e)
{
form2 = new Form2();
form2.Show();
}
//"恢复修改"button函数的功能,转向Form3的界面.
private void button4_Click(object sender, System.EventArgs e)
{
form3 = new Form3();
form3.Show();
}
//"修改位置"button函数的功能,转向Form4的界面.
private void button7_Click(object sender, System.EventArgs e)
{
form4 = new Form4();
form4.Show();
}
//"卸载控制"button函数的功能,将卸载的控制码赋值为ds0000.
private void button8_Click(object sender, System.EventArgs e)
{
removing = "ds0000";
}
//"请求连接"button函数的功能.
private void button1_Click(object sender, System.EventArgs e)
{
//记录窗口显示操作记录
richTextBox1.AppendText("for connecting " + textBox1.Text + "\r");
int port = 6678;
//如果连接不成功,显示错误信息.
try
{
client = new TcpClient(textBox1.Text, port);
}
catch
{
MessageBox.Show("No server on line!Please enter the right IP address.");
richTextBox1.AppendText("No server on line!Please enter the right IP address." + "\r");
}
}
//"测试连接"button函数的功能.
private void button2_Click(object sender, System.EventArgs e)
{
//控制记录窗口显示操作记录
richTextBox1.AppendText("Testing connecting" + "\r");
try
{
stream = client.GetStream();
if (stream.CanWrite)
{
string control = "Tesing";
byte[] by = System.Text.Encoding.ASCII.GetBytes(control.ToCharArray());
stream.Write(by, 0, by.Length);
stream.Flush();
thread = new Thread(new ThreadStart(receive));
thread.Start();
}
}
catch (Exception ee)
{
richTextBox1.AppendText(ee.Message + "\r");
MessageBox.Show(ee.Message);
}
}
//receive函数,反馈服务器的连接与被控制状态.反馈控制码为3位.
public void receive()
{
byte[] bb = new byte[3];
int i = stream.Read(bb, 0, 3);
//用字符串变量ss表示控制反馈码
string ss = System.Text.Encoding.ASCII.GetString(bb);
//con代表连接成功的服务器反馈码
if (ss == "con")
{
MessageBox.Show("Connecting Well!");
richTextBox1.AppendText("with " + textBox1.Text + " Connecting Well。" + "\r");
}
//ctr代表控制成功的服务器反馈码
if (ss == "ctr")
{
richTextBox1.AppendText(control + "Controling Well" + "\r");
MessageBox.Show(control + "Controling Well");
}
}
//"控制生效"button函数的功能,发送控制信号.
private void button9_Click(object sender, System.EventArgs e)
{
//发送修改注册表的控制码.
if (radioButton1.Checked)
{
control = form2.AttackSingal;
}
//发送恢复修改的控制码.
else if (radioButton2.Checked)
{
control = form3.RollbackSingal;
}
//发送修改控制程序位置的控制码.
else if (radioButton5.Checked)
{
control = form4.MovingSingal;
}
//发送卸载控制程序的控制码.
else if (radioButton6.Checked)
{
control = removing;
}
//无控制信息.
if (control == "000000")
{
MessageBox.Show("No aim.No control singal to be sent.");
richTextBox1.AppendText("No aim.No control singal to be sent." + "\r");
}
//控制测试显示.
else if (control != "000000")
{
try
{
richTextBox1.AppendText(control + " Waiting for singal" + "\r");
stream = client.GetStream();
if (stream.CanWrite)
{
byte[] by = System.Text.Encoding.ASCII.GetBytes(control.ToCharArray());
stream.Write(by, 0, by.Length);
stream.Flush();
thread = new Thread(new ThreadStart(receive));
thread.Start();
}
}
catch
{
richTextBox1.AppendText("No servers connecting!No controling." + "\r");
MessageBox.Show("No servers connecting!No controling." + "\r");
}
}
}
//"保存记录"button函数的功能.
private void button10_Click(object sender, System.EventArgs e)
{
StreamWriter sw = null;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
sw = new StreamWriter(saveFileDialog1.FileName, false, System.Text.Encoding.Unicode);
sw.Write(richTextBox1.Text);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
finally
{
if (sw != null)
{
sw.Close();
}
}
}
}
//"查看记录"button函数的功能.
private void button11_Click(object sender, System.EventArgs e)
{
string aa;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
aa = File.OpenText(openFileDialog1.FileName).ReadToEnd();
richTextBox1.AppendText(aa);
File.OpenText(openFileDialog1.FileName).Close();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -