Winforms 我可以只为我想要的webbrowser设置代理吗?

Winforms 我可以只为我想要的webbrowser设置代理吗?,winforms,Winforms,我找到了在stackoverflow上的webbrowser中设置代理的方法 但是,此代码是所有web浏览器的代理设置。我在表单中有多个web浏览器,我只想代理其中的一个web浏览器 我找到了这个,但对我没有帮助 如果创建一个可以连接到代理然后继承webbrowser的自定义usercontrol,是否可以解决此问题 任何有用的信息都将不胜感激在切换到chromium窗口后,我能够设置每个代理 public struct Struct_INTERNET_PROXY_INFO { pu

我找到了在stackoverflow上的webbrowser中设置代理的方法

但是,此代码是所有web浏览器的代理设置。我在表单中有多个web浏览器,我只想代理其中的一个web浏览器

我找到了这个,但对我没有帮助

如果创建一个可以连接到代理然后继承webbrowser的自定义usercontrol,是否可以解决此问题


任何有用的信息都将不胜感激

在切换到chromium窗口后,我能够设置每个代理

public struct Struct_INTERNET_PROXY_INFO
{
    public int dwAccessType;
    public IntPtr proxy;
    public IntPtr proxyBypass;
};

[DllImport("wininet.dll", SetLastError = true)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);

//to activate use like this strProxy="85.45.66.25:3633"
//to deactivate use like this strProxy=":"
public static void RefreshIESettings(string strProxy)
{
    try
    {
        const int INTERNET_OPTION_PROXY = 38;
        const int INTERNET_OPEN_TYPE_PROXY = 3;

        Struct_INTERNET_PROXY_INFO struct_IPI;

        // Filling in structure 
        struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
        struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
        struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");

        // Allocating memory 
        IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));

        // Converting structure to IntPtr 
        Marshal.StructureToPtr(struct_IPI, intptrStruct, true);

        bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));
    }
    catch (Exception ex)
    {

        //TB.ErrorLog(ex);
    }
}

private void SomeFunc()
{
     RefreshIESettings("1.2.3.4:8080");
     //or RefreshIESettings("http://1.2.3.4:8080"); //both worked
     //or RefreshIESettings("http=1.2.3.4:8080"); //both worked

     System.Object nullObject = 0;
     string strTemp = "";
     System.Object nullObjStr = strTemp;
     WebBrowser1.Navigate("http://willstay.tripod.com");
}