diff --git a/shadowsocks-csharp/Form1.Designer.cs b/shadowsocks-csharp/Form1.Designer.cs
index 20273050..b1ddb8e4 100755
--- a/shadowsocks-csharp/Form1.Designer.cs
+++ b/shadowsocks-csharp/Form1.Designer.cs
@@ -51,6 +51,7 @@
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
+ this.EnableItem = new System.Windows.Forms.ToolStripMenuItem();
this.tableLayoutPanel1.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
this.panel1.SuspendLayout();
@@ -200,38 +201,38 @@
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.EnableItem,
this.ConfigItem,
this.aboutToolStripMenuItem,
this.toolStripSeparator2,
this.QuitItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;
- this.contextMenuStrip1.Size = new System.Drawing.Size(112, 76);
+ this.contextMenuStrip1.Size = new System.Drawing.Size(153, 120);
//
// ConfigItem
//
- this.ConfigItem.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
this.ConfigItem.Name = "ConfigItem";
- this.ConfigItem.Size = new System.Drawing.Size(111, 22);
+ this.ConfigItem.Size = new System.Drawing.Size(152, 22);
this.ConfigItem.Text = "Config";
this.ConfigItem.Click += new System.EventHandler(this.Config_Click);
//
// aboutToolStripMenuItem
//
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
- this.aboutToolStripMenuItem.Size = new System.Drawing.Size(111, 22);
+ this.aboutToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.aboutToolStripMenuItem.Text = "About";
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
- this.toolStripSeparator2.Size = new System.Drawing.Size(108, 6);
+ this.toolStripSeparator2.Size = new System.Drawing.Size(149, 6);
//
// QuitItem
//
this.QuitItem.Name = "QuitItem";
- this.QuitItem.Size = new System.Drawing.Size(111, 22);
+ this.QuitItem.Size = new System.Drawing.Size(152, 22);
this.QuitItem.Text = "Quit";
this.QuitItem.Click += new System.EventHandler(this.Quit_Click);
//
@@ -279,6 +280,15 @@
this.panel1.Size = new System.Drawing.Size(164, 30);
this.panel1.TabIndex = 1;
//
+ // EnableItem
+ //
+ this.EnableItem.Checked = true;
+ this.EnableItem.CheckState = System.Windows.Forms.CheckState.Checked;
+ this.EnableItem.Name = "EnableItem";
+ this.EnableItem.Size = new System.Drawing.Size(152, 22);
+ this.EnableItem.Text = "Enable";
+ this.EnableItem.Click += new System.EventHandler(this.EnableItem_Click);
+ //
// Form1
//
this.AcceptButton = this.button1;
@@ -329,6 +339,7 @@
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Panel panel1;
+ private System.Windows.Forms.ToolStripMenuItem EnableItem;
}
}
diff --git a/shadowsocks-csharp/Form1.cs b/shadowsocks-csharp/Form1.cs
index e0294d71..9e0ff825 100755
--- a/shadowsocks-csharp/Form1.cs
+++ b/shadowsocks-csharp/Form1.cs
@@ -131,5 +131,18 @@ namespace shadowsocks_csharp
showWindow();
}
+ private void EnableItem_Click(object sender, EventArgs e)
+ {
+ EnableItem.Checked = !EnableItem.Checked;
+ if (EnableItem.Checked)
+ {
+ SystemProxy.Enable();
+ }
+ else
+ {
+ SystemProxy.Disable();
+ }
+ }
+
}
}
diff --git a/shadowsocks-csharp/SystemProxy.cs b/shadowsocks-csharp/SystemProxy.cs
index e62f84b3..fe10bd5f 100755
--- a/shadowsocks-csharp/SystemProxy.cs
+++ b/shadowsocks-csharp/SystemProxy.cs
@@ -15,28 +15,28 @@ namespace shadowsocks_csharp
public const int INTERNET_OPTION_REFRESH = 37;
static bool settingsReturn, refreshReturn;
- public void Enable()
+ public static void UpdateIE()
{
- RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
- registry.SetValue("ProxyEnable", 1);
- registry.SetValue("ProxyServer", "127.0.0.1:8123");
-
// These lines implement the Interface in the beginning of program
// They cause the OS to refresh the settings, causing IP to realy update
settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
}
- public void Disable()
+ public static void Enable()
+ {
+ RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
+ registry.SetValue("ProxyEnable", 1);
+ registry.SetValue("ProxyServer", "127.0.0.1:8123");
+ SystemProxy.UpdateIE();
+ }
+
+ public static void Disable()
{
RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
registry.SetValue("ProxyEnable", 0);
registry.SetValue("ProxyServer", "");
-
- // These lines implement the Interface in the beginning of program
- // They cause the OS to refresh the settings, causing IP to realy update
- settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
- refreshReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
+ SystemProxy.UpdateIE();
}
}
}
diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj
index 48a46982..7541b482 100755
--- a/shadowsocks-csharp/shadowsocks-csharp.csproj
+++ b/shadowsocks-csharp/shadowsocks-csharp.csproj
@@ -99,6 +99,7 @@
+
Form1.cs
Designer