-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
282 lines (240 loc) · 9.46 KB
/
Form1.cs
File metadata and controls
282 lines (240 loc) · 9.46 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Configuration;
using System.Web;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
namespace bark
{
public partial class Form1 : Form
{
int proxy_flag = 1;
private void Form1_SizeChanged(object sender, EventArgs e)
{
//判断是否选择的是最小化按钮
if (WindowState == FormWindowState.Minimized)
{
//托盘显示图标等于托盘图标对象
//注意notifyIcon1是控件的名字而不是对象的名字
//notifyIcon1.Icon = ico;
//隐藏任务栏区图标
this.ShowInTaskbar = false;
//图标显示在托盘区
notifyIcon1.Visible = true;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// 注意判断关闭事件reason来源于窗体按钮,否则用菜单退出时无法退出!
if (e.CloseReason == CloseReason.UserClosing)
{
//取消"关闭窗口"事件
e.Cancel = true; // 取消关闭窗体
//使关闭时窗口向右下角缩小的效果
WindowState = FormWindowState.Minimized;
this.notifyIcon1.Visible = true;
//this.m_cartoonForm.CartoonClose();
this.Hide();
return;
}
}
//双击图标显示窗口
private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.Visible)
{
this.WindowState = FormWindowState.Minimized;
this.notifyIcon1.Visible = true;
this.Hide();
}
else
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.Activate();
}
}
public Form1()
{
InitializeComponent();
bool flag = false;
System.Threading.Mutex mutex = new System.Threading.Mutex(true, "bark", out flag);
if (!flag)
{
MessageBox.Show("程序已运行", "请确定", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Environment.Exit(0);//退出程序
//Application.Exit();
}
}
//修改url_key
private void button2_Click(object sender, EventArgs e)
{
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["url_key"].Value = textBox1.Text;
config.Save();
MessageBox.Show("修改成功");
}
private void button1_Click(object sender, EventArgs e)
{
string url="";
if (radioButton1.Checked)
{
url = textBox1.Text + textBox3.Text;
}
else if (radioButton2.Checked)
{
url = textBox1.Text + textBox2.Text + "/" + textBox3.Text;
}
else if (radioButton3.Checked)
{
textBox2.Enabled = false;
textBox3.Enabled = false;
url =textBox1.Text + "网址?url=" + textBox4.Text;
}
else if (radioButton4.Checked)
{
textBox4.Enabled = false;
url = textBox1.Text + textBox3.Text+ "?automaticallyCopy=1 ";
//MessageBox.Show(url);
}
UriBuilder uri = new UriBuilder(url);
if (proxy_flag == 1) {
WebProxy myproxy = new WebProxy("http://" + textBox5.Text + ":" + textBox6.Text); //添加代理服务器
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate; //代理服务器ssl证书
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.Uri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
var str = reader.ReadToEnd();
//MessageBox.Show(str);
}
private void Form1_Load(object sender, EventArgs e)
{
//读取配置
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
textBox1.Text=config.AppSettings.Settings["url_key"].Value;
textBox5.Text= config.AppSettings.Settings["proxy_ip"].Value;
textBox6.Text = config.AppSettings.Settings["proxy_port"].Value;
}
private void 推送剪切板ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("你确定要退出?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
this.notifyIcon1.Visible = false;
this.Close();
Dispose();
System.Environment.Exit(System.Environment.ExitCode);
}
}
//手动打开窗口推送
private void 打开并手动推动ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.Visible)
{
this.WindowState = FormWindowState.Minimized;
this.notifyIcon1.Visible = true;
this.Hide();
}
else
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.Activate();
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
textBox2.Enabled = false;
textBox3.Enabled = true;
textBox4.Enabled = false;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox4.Enabled = false;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
textBox2.Enabled = false;
textBox3.Enabled = false;
textBox4.Enabled = true;
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
textBox2.Enabled = false;
textBox3.Enabled = true;
textBox4.Enabled = false;
}
private void 推送剪切板内容ToolStripMenuItem_Click(object sender, EventArgs e)
{
UriBuilder uri = new UriBuilder(textBox1.Text+Clipboard.GetText());
if (proxy_flag == 1) {
WebProxy myproxy = new WebProxy("http://" + textBox5.Text + ":" + textBox6.Text);//添加代理服务器
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;//代理服务器ssl证书
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri.Uri);
//request.Proxy = myproxy;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
var str = reader.ReadToEnd();
MessageBox.Show("推送:" + "'"+Clipboard.GetText()+"'"+"成功");
}
//代理服务器ssl证书函数
private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
//为了通过证书验证,总是返回true
return true;
}
private void button3_Click(object sender, EventArgs e)
{
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["proxy_ip"].Value = textBox5.Text;
config.AppSettings.Settings["proxy_port"].Value = textBox6.Text;
config.Save();
MessageBox.Show("修改成功代理服务器成功");
}
private void label7_Click(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
proxy_flag = 1;
textBox5.Enabled = true;
textBox6.Enabled = true;
}
else
{
proxy_flag = 0;
textBox5.Enabled = false;
textBox6.Enabled = false;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text.Trim().Substring(textBox1.Text.Trim().Length - 1, 1) == "/")
{
textBox1.Text = textBox1.Text.Trim();
}
else
{
textBox1.Text = textBox1.Text + "/";
}
}
}
}