在窗体 InitializeComponent();
后加 代码 注册 事件 看看
this.timer_Tick += new EventHandler(timer_Tick);

解决方案 »

  1.   

    晕,你的SetText是成员函数,不是静态函数,当然直接用类名调用是不行的.
    要声明为static才可以.
      

  2.   

    重写吧:
    1、一个UserControl类的对象userControl1包含有一个TextBox类的textBox1。
    2、在Form1内部的
    private void timer_Tick(object sender, System.EventArgs e)
    {
        userControl1.textBox1.text="XXX";//成功
    }3、但在Form1内部的
    private void timer_Tick(object sender, System.EventArgs e)
    {
        ABC1.SetText("XXX");
    }class  ABC
    {
       public void SetText(String xxx)
       {
          userControl1.textBox1.text=xxx;//失败
       }
    }
    备注:
    1、跟踪调试一点问题都没有,但是textBox1的Text就是不变。
    2、this.timer_Tick += new EventHandler(timer_Tick) 加了,事件也触发了;
    3、跟踪 userControl1.textBox1.text=xxx;这一条语句也执行了,XXX变量有值,但是textBox1.Text就是不变。
      

  3.   

    class  ABC
    {
       public void SetText(String xxx)
        {
             userControl1.TextBox.text=xxx;//失败了
         }
    }
    再试试。理论上没有问题,另外楼上的类和实例的关系的答案似乎没有什么意义^_^
      

  4.   

    哦,你class abc里面的userControl1是那里来的?
    这个东西你在这个类里面没有实例化吧。
      

  5.   

    lx1920(我思,谁在?) 厉害,确实你的类和对象没有弄清楚。你的abc里面怎么访问userControl1
      

  6.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime.InteropServices;namespace SysMind
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class FormMain : System.Windows.Forms.Form
    {
    SysMind.RemindItemList.RemindItem_OA_SendFile_ZBX sendFile_ZBX1 =new SysMind.RemindItemList.RemindItem_OA_SendFile_ZBX() ; ManageRemind mRemind;
    byte[] bytesSound;
    Icon icoSound; 
    private const int SND_ASYNC  = 0x1;
    private System.Windows.Forms.MenuItem menuItem_SeeMind;
    private System.Windows.Forms.MenuItem menuItem_CloseMind;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.GroupBox groupBox2;
    private System.Windows.Forms.Panel panel_Left;
    private System.Windows.Forms.Label label_Top;
    public System.Windows.Forms.Timer timer;
    private const int SND_MEMORY = 0x4; /// <summary>
    /// 导入Sound支持Dll库
    /// </summary>
    [DllImport("winmm.dll")]
    private static extern int sndPlaySoundA(byte[] lpszSoundName, int uFlags);

    /// <summary>
    /// 是否允许关闭窗口
    /// </summary>
    private bool isClose=false; private System.Windows.Forms.ContextMenu contextMenu;
    private System.Windows.Forms.NotifyIcon notifyIcon;
    private System.ComponentModel.IContainer components; private void IniData()
    {
    notifyIcon.Icon = this.Icon;
    notifyIcon.ContextMenu = this.contextMenu;
    notifyIcon.Text = this.Text;
    notifyIcon.Visible = true;
    try
    {
    //将a1.wav添加入工程并设置为嵌入的资源
    //现在是将它读入内存备用
    Type t=this.GetType();
    System.Reflection.Assembly a=t.Assembly;
    System.IO.Stream streamSound=a.GetManifestResourceStream(t.Namespace+".a1.wav");
    bytesSound=new byte[streamSound.Length];
    streamSound.Read(bytesSound,0, bytesSound.Length);
    streamSound.Close(); System.IO.Stream streamSoundPic=a.GetManifestResourceStream(t.Namespace+".sound.ico");

    this.icoSound=new Icon(streamSoundPic);
    }
    catch(Exception e2)
    {
    this.notifyIcon.Text = this.Text; } RegisteRemindItem();
    }
    public FormMain(String employee_Code)
    {
    this.mRemind=new ManageRemind(employee_Code);
    InitializeComponent();
    IniData(); string sql=" SELECT  HR_Employee.EMP_Code,  HR_Employee.EMP_Name,  "+
    "  HR_Department.DEP_Code,  HR_Department.DEP_Name "+
    "  FROM  HR_Employee INNER JOIN "+
    "  HR_Department ON  "+
    "  HR_Employee.EMP_DEPCode =  HR_Department.DEP_Code ";
    System.Data.SqlClient.SqlDataAdapter adapter=new System.Data.SqlClient.SqlDataAdapter(sql+ " where EMP_Code='"+employee_Code.Trim()+"'",Genius.LZZLS.SystemFrameworks.SystemFramework.CONNECT);
    DataTable table=new DataTable();
    adapter.Fill(table);

    if(table.Rows.Count == 1)
    {
    this.label_Top.Text="当前用户:"+table.Rows[0]["EMP_Name"].ToString()+"  部门:"+table.Rows[0]["DEP_Name"].ToString();
    }
    else
    {
    this.label_Top.Text="当前提醒用户不存在(employee_Code)";

    }

    } /// <summary>
    /// 注册提醒监控项目
    /// </summary>
    private void RegisteRemindItem()
    {
    SysMind.RemindItemList.RemindItem_OA_SendFile_SJX sendFile_SJX= new SysMind.RemindItemList.RemindItem_OA_SendFile_SJX();
    sendFile_SJX.SetSubject("sdf四面推开");
    this.mRemind.AddItem( new SysMind.RemindItemList.RemindItem_OA_SendFile_SJX() );
    AddItem(sendFile_SJX); SysMind.RemindItemList.RemindItem_OA_SendFile_ZBX sendFile_ZBX =new SysMind.RemindItemList.RemindItem_OA_SendFile_ZBX() ;
    this.mRemind.AddItem( new SysMind.RemindItemList.RemindItem_OA_SendFile_ZBX() );
    AddItem(sendFile_ZBX); this.mRemind.AddItem( sendFile_ZBX1);
    AddItem(sendFile_ZBX1); } private void AddItem(System.Windows.Forms.Control c)
    {
    c.Dock=System.Windows.Forms.DockStyle.Top;
    this.panel_Left.Controls.Add(c);
    }
    #region 设计器生成
    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } ..........................
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new FormMain("00156"));
    }
    #endregion #region 托盘控制
    /// <summary>
    /// 播放声音
    /// </summary>
    private void PlaySound()
    {
    try
    {
    //播放缓存
    sndPlaySoundA(bytesSound, SND_MEMORY);
    }
    catch(Exception e2)
    {
    }
    }
    /// <summary>
    /// 有新消息
    /// </summary>
    private void NewMessage()
    {
    this.PlaySound();
    this.notifyIcon.Icon=this.icoSound;
    }
    /// <summary>
    /// 双击托盘图标
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void notifyIcon_DoubleClick(object sender, System.EventArgs e)
    { if (this.WindowState == FormWindowState.Minimized)
    {
    this.Visible=true;
    this.WindowState =  FormWindowState.Normal;
    this.Activate();
    }
    else {
    WindowState=FormWindowState.Minimized;
    this.Visible=false;
    } }
    /// <summary>
    /// 窗口大小变更事件 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void FormMain_Resize(object sender, System.EventArgs e)
    {
    if (this.WindowState == FormWindowState.Minimized) 
    {
    this.Visible = false;
    this.notifyIcon.Icon = this.Icon;
    }
    } /// <summary>
    /// 关闭提醒监控系统事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void FormMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    WindowState=FormWindowState.Minimized;
    this.Visible=false;
    this.notifyIcon.Icon = this.Icon;
    e.Cancel=!this.isClose;
    } /// <summary>
    /// 打开提醒监控系统
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void menuItem_SeeMind_Click(object sender, System.EventArgs e)
    {
    this.Visible=true;
    this.WindowState =  FormWindowState.Normal;
    this.Activate();
    } /// <summary>
    /// 关闭提醒监控系统
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void menuItem_CloseMind_Click(object sender, System.EventArgs e)
    {
    this.isClose=true;
    this.Close();
    }
    #endregion /// <summary>
    /// 时钟定期事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void timer_Tick(object sender, System.EventArgs e)
    {
    lock(this)
    {
    sendFile_ZBX1.SetSubject("xxxx");
    this.mRemind.RefurbishRemindData();
    }

    }
    }
    }