我在一个form2中连接数据库,做了个用户密码进入窗口,正确就可以进入form1,但我想在另一个form1显示在form2中取得的那个用户名出来,应如何做,好高们帮帮忙好吗?

解决方案 »

  1.   

    winForm or webForm?win 的话调用那一个窗口的取用户名的方法web 的话放在Session中或脚本传递.
      

  2.   

    你跟着我做:
    先做一个发分发消息的类:using System;namespace Community
    {
    /// <summary>
    /// Notify 的摘要说明。
    /// </summary>
    public class Notify
    {
    protected static Notify m_notify=null;
    public delegate void NotifyEvent(object sender,NotifyEventArgs e);
    public event NotifyEvent OnNotifyEvent;
    public Notify()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    }

    public static Notify Instance
    {
    get
    {
    if (m_notify == null) 
    m_notify = new Notify(); 
    return m_notify;  }
    } public void SendMessage(int code, string message) 

    NotifyEventArgs e = new NotifyEventArgs(code, message); 
    if ( OnNotifyEvent != null) 
    OnNotifyEvent(this, e); 

    } ///////////
    public class NotifyEventArgs:System.EventArgs 
    {
    protected int m_nCode;
    protected string m_strMessage = string.Empty; 
    public NotifyEventArgs()
    {
    }
    public NotifyEventArgs(int code,string message)
    {
    m_nCode=code;
    m_strMessage=message;
    }
    public int Code 

    get { return m_nCode;} 
    set { m_nCode = value;} 

    public string Message 

    get { return m_strMessage;} 
    set 

    m_strMessage = value; 
    if (m_strMessage == null) 
    m_strMessage = string.Empty; 

    }
    #region Common Infomation 
    public const int ToAnimation= 1; 
    public const int ToDump=2;
    // public const int CompanyInfo = 1; 
    // public const int ProjectInfo = 2; 
    // public const int TaskInfo = 3; 
    // public const int Opportunity = 4; 
    // public const int Contactor = 5; 
    // public const int EmployeeInfo = 6; 
    // public const int DepartmentInfo = 7; 
    // public const int AdvCityInfo = 8; 
    #endregion 
    }
    }
      

  3.   

    接下来在Form2 的构造函数中加上如下语句:Notify.Instance .OnNotifyEvent +=new Community.Notify.NotifyEvent(Instance_OnNotifyEvent);
      

  4.   

    对了刚才应该是form1的构造函数:form1中加上下面的话:private void Instance_OnNotifyEvent(object sender ,NotifyEventArgs e)
    {
    int i=Convert.ToInt32(e.Message );
    if(e.Code ==NotifyEventArgs.ToForm1)
    {
                                      MessageBox.show("我得到了Form2的值");
    }
    }按这种方式,你自已扩展!!我的程序都是这么做的
      

  5.   

    Form2中:
    Notify.Instance .SendMessage (Community.NotifyEventArgs .ToForm1,"这是Form2的信息");
      

  6.   

    winform也是可行的,总体上的思路就是自己写一个小小的消息机制,在form1 load时建立委托,
    写好委托事件,在form2 中改变数据库时发送消息到form1,此时form1接收到form2中的消息,然后开始执行你所写的委托事件,你在委托事件中重取数据库就可以得到最新的用户信息。
      

  7.   

    窗体之间的数据交互
    http://blog.csdn.net/zhzuo/archive/2004/04.aspx
      

  8.   

    把form1的构造函数重写,可以传入参数,把用户名传入就可以了
      

  9.   

    定义public属性,在第一个form中new第二个form时把this传给第二个form
      

  10.   

    太麻烦了。昏
    这么写。
    Form2 good=new Form2//good自定义
    good.v=user;//v首先要在Form2里面做全局变量如: pubilc srting v; //user是你用户名筐的值
    good.show();//打开
    在给你个思路。
    在连接数据时你不是要进行IF判断是否用户是否正确!加在正确后进入另个连接里面
    如:
    if (myReader.Read()==true)
    {
    Form3 mscr=new Form3();
    this.Hide ();
    mscr.shuju=accNo;
    mscr.Show();
    }
    else{}