用数组或者哈西表作为全局静态变量保存登陆者名单,判断时看看数组中是否存在
可用Panel作为控件,图片的容器,到时候,如果登陆 则visiable           

解决方案 »

  1.   

    //在窗体一适当位置加入
    private static string username,flag;
    Mainfrm mainfrm = new Mainfrm(username,flag);
    mainfrm.Show();
    //窗体二适当位置加入
    public string user,type;
    public Mainfrm(string username, string flag)
    {
    user = username;
    type = flag;
    }
    //基本思想是给窗体二设置适当参数,有窗体一传递过来
      

  2.   

    晕   看来大家误会我的意思了   我不是要判断某个用户登录时候又没有权限举例说吧:我是要登录一个不属于我的论坛,用户名和密码我都有我要在winform C#窗体里面实现登录后   在用sockets或者webrequest等方式获取没有登录前被Session或者cookies保护的页面信息
      

  3.   

    你可以到下面去找一个叫CSDN论坛助手的东东...某高手写的,记不起名字了.
    上面可能有你想要的资料吧,有源码的.
    ftp://qydn.vicp.net/ftp://211.140.160.74
    哪个我记不太清了,你去找下吧...如果没有了把你的Email告诉我,我给你发一个
      

  4.   

    using System;
    using System.IO;
    using System.Net;
    using System.Runtime.CompilerServices;
    using System.Text;
    using System.Web;namespace MyCommon
    {
    /// <summary>
    /// MyHTML 的摘要说明。
    /// </summary>
    public class MyHTML
    {
    private string cookieContainer="";
    public string CookieContainer
    {
    get
    {
    return cookieContainer;
    }
    set
    {
    cookieContainer = value;
    }
    } public string Login(string url, string paramList)
    {
    HttpWebResponse httpWebResponse=null;
    try
    {
    HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
    httpWebRequest.Method = "POST";
    httpWebRequest.ContentType = "application/x-www-form-urlencoded";
    httpWebRequest.AllowAutoRedirect = false;
    CookieContainer c = new CookieContainer();
    httpWebRequest.CookieContainer = c;
    StringBuilder sb= new StringBuilder();
    char[] ch = new char[]{'?', '=', '&'};
    if (paramList != null)
    {
    int j;
    for (int i = 0; i < paramList.Length; i = j + 1)
    {
    j = paramList.IndexOfAny(ch, i);
    if (j == -1)
    {
    sb.Append(HttpUtility.UrlEncode(paramList.Substring(i)));
    break;
    }
    else
    {
    sb.Append(HttpUtility.UrlEncode(paramList.Substring(i, j - i)));
    sb.Append(paramList.Substring(j, 1));
    }
    }
    byte [] b = Encoding.Default.GetBytes(sb.ToString());
    httpWebRequest.ContentLength = b.Length;
    Stream s = httpWebRequest.GetRequestStream();
    s.Write(b, 0, b.Length);
    s.Close();
    }
    else
    {
    httpWebRequest.ContentLength = 0;
    }
    httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    cookieContainer = httpWebRequest.CookieContainer.GetCookieHeader(new Uri(url));
    }
    catch (Exception e)
    {
    return e.Message;
    }
    finally
    {
    if (httpWebResponse != null)
    {
    httpWebResponse.Close();
    }
    }
    return cookieContainer;
    } public string GetHTMLPage(string url, string paramList)
    {
    HttpWebResponse httpWebResponse=null;
    StringBuilder getHTMLPage = new StringBuilder();
    try
    {
    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    httpWebRequest.Method = "POST";
    httpWebRequest.KeepAlive = true;
    httpWebRequest.ContentType = "application/x-www-form-urlencoded";
    CookieContainer c = new CookieContainer();
    httpWebRequest.CookieContainer = c;
    httpWebRequest.CookieContainer.SetCookies(new Uri(url), cookieContainer);
    StringBuilder sb = new StringBuilder();
    char[] ch = new char[]{'?', '=', '&'};
    if (paramList != null)
    {
    int j;
    for (int i = 0; i < paramList.Length; i = j + 1)
    {
    j = paramList.IndexOfAny(ch, i);
    if (j == -1)
    {
    sb.Append(HttpUtility.UrlEncode(paramList.Substring(i)));
    break;
    }
    else
    {
    sb.Append(HttpUtility.UrlEncode(paramList.Substring(i, j - i)));
    sb.Append(paramList.Substring(j, 1));
    }
    }
    byte[] b = Encoding.Default.GetBytes(sb.ToString());
    httpWebRequest.ContentLength = b.Length;
    Stream s = httpWebRequest.GetRequestStream();
    s.Write(b, 0, b.Length);
    s.Close();
    }
    else
    {
    httpWebRequest.ContentLength = 0;
    }
    httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.Default);
    getHTMLPage.Append(sr.ReadToEnd());
    }
    catch (Exception e)
    {
    getHTMLPage.Append(e.ToString());
    }
    finally
    {
    if (httpWebResponse != null)
    {
    httpWebResponse.Close();
    }
    }
    return getHTMLPage.ToString();
    }
    }
    }