C# 用户控件的Load事件不能执行

问题描述

C# 用户控件的Load事件不能执行

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.IO;
using OpenPOP.POP3;
using System.Collections;
using OpenPOP.MIMEParser;
using System.Threading;
using mymail.sqlDao;
using System.Data.SqlClient;
using mymail;

namespace mymail
{
public partial class inbox : UserControl
{

    public inbox()
    {
        InitializeComponent();
    }

    private void inbox_Load(object sender, EventArgs e)
    {
        msgs.Clear();

        //listMessages.Nodes.Clear();//邮件列表
        listAttachments.Nodes.Clear();//附件列表
        listView1.Clear();//清除空间中所有项
        //button2.Enabled = false;
        //button3.Enabled = false;
        //ReceiveMails();
    }

解决方案

在你的inbox.designer.cs中的InitializeComponent的定义中有没有挂钩事件:
this.Load += new EventHandler(this.inbox_Load);

解决方案二:

这是完整代码,实在不清楚是哪里有问题?求大神告知。。。急急急!!!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.IO;
using OpenPOP.POP3;
using System.Collections;
using OpenPOP.MIMEParser;
using System.Threading;
using mymail.sqlDao;
using System.Data.SqlClient;
using mymail;

namespace mymail
{
public partial class inbox : UserControl
{
private POPClient popClient = new POPClient();
private Hashtable msgs = new Hashtable();

    public inbox()
    {
        InitializeComponent();
    }

    private void inbox_Load(object sender, EventArgs e)
    {
        msgs.Clear();

        //listMessages.Nodes.Clear();//邮件列表
        listAttachments.Nodes.Clear();//附件列表
        listView1.Clear();//清除空间中所有项
        //button2.Enabled = false;
        //button3.Enabled = false;
        //ReceiveMails();
    }

    private void ReceiveMails()
    {
        //EMMS emms = new EMMS();
        //string username = emms.Tranuser;
        string username = "smj";
        //string userpasswd = emms.Tranpasswd;
        UserDao testuser1 = new UserDao();
        SqlConnection con1 = testuser1.GetCon();
        SqlCommand sqlstr1 = new SqlCommand();
        sqlstr1.Connection = con1;
        sqlstr1.CommandText = "select * from UserMail where username = '" + username + "'";
        SqlDataReader custDR1 = sqlstr1.ExecuteReader();
        ArrayList accounts = new ArrayList();
        while (custDR1.Read())
        {
            string account = custDR1.GetString(custDR1.GetOrdinal("account")).Trim();
            accounts.Add(account);
        }
        testuser1.GetClose();

        ArrayList inmailservers = new ArrayList();
        ArrayList inports = new ArrayList();
        ArrayList inpasswords = new ArrayList();

        //MessageBox.Show(accounts[1].ToString().Trim());
        //MessageBox.Show(accounts.Count.ToString());

        for (int i = 0; i < accounts.Count;i++ )
        {
            UserDao testuser2 = new UserDao();
            SqlConnection con2 = testuser2.GetCon();
            SqlCommand sqlstr2 = new SqlCommand();
            sqlstr2.Connection = con2;
            sqlstr2.CommandText = "select * from MailAccounts where account = '" + accounts[i].ToString().Trim() + "'";
            SqlDataReader custDR2 = sqlstr2.ExecuteReader();
            while (custDR2.Read())
            {
                string inmailserver = custDR2.GetString(custDR2.GetOrdinal("inmailserver")).Trim();
                inmailservers.Add(inmailserver);
                string inport = custDR2.GetString(custDR2.GetOrdinal("inport")).Trim();
                inports.Add(inport);
                string inpassword = custDR2.GetString(custDR2.GetOrdinal("inpassword")).Trim();
                inpasswords.Add(inpassword);
            }
            testuser2.GetClose();
        }

        popClient.Disconnect();
        popClient.Connect(inmailservers[1].ToString().Trim(), int.Parse(inports[1].ToString().Trim()));
        popClient.Authenticate(accounts[1].ToString().Trim(),inpasswords[1].ToString().Trim());

        int Count = popClient.GetMessageCount();//读取邮件总数

        msgs.Clear();
        //添加一列
        //this.listView1.Columns.Add("列标题1", 120, HorizontalAlignment.Left); //一步添加
        this.listView1.BeginUpdate();
        for (int i = Count; i >= 1; i -= 1)
        {
            OpenPOP.MIMEParser.Message m = popClient.GetMessageHeader(i);//获得邮件头
            ListViewItem lvi = new ListViewItem();

            //lvi.ImageIndex = i;     //通过与imageList绑定,显示imageList中第i项图标

            if (m != null)
            {
                if (m.Subject.Length > 0)
                    lvi.Text = m.Subject;
                else
                    lvi.Text = "无主题";
            }
            this.listView1.Items.Add(lvi);
            //Thread.Sleep(1);
        }
        this.listView1.EndUpdate();  //结束数据处理,UI界面一次性绘制。
        MessageBox.Show(this, "邮件接收完毕!");
    }

    private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        ListViewHitTestInfo li = listView1.HitTest(e.Location);
        if (li != null && li.Item != null)
            li.Item.Checked = !li.Item.Checked; //改这样
    }

    private void listView1_ItemActivate(object sender, EventArgs e)
    {
        int totalindex = listView1.Items.Count;
        int index = totalindex - listView1.SelectedItems[0].Index;
        OpenPOP.MIMEParser.Message m = popClient.GetMessage(index, false);//读出邮件全部内容
        if (msgs["msg" + index.ToString()] == null)
            msgs.Add("msg" + index.ToString(), m);//存入哈希表
        if (m != null)
        {
            if (m.MessageBody.Count > 0)
            {
                //txtMessage.Text = (string)m.MessageBody[m.MessageBody.Count - 1];
                webBrowser1.DocumentText = (string)m.MessageBody[m.MessageBody.Count - 1];
            }
            listAttachments.Nodes.Clear();
            string filenm = "";
            for (int i = 0; i < m.AttachmentCount; i++)
            {
                OpenPOP.MIMEParser.Attachment att = m.GetAttachment(i);//获取邮件附件列表
                filenm = m.GetAttachmentFileName(att);
                if (filenm != "body.html" && filenm != "body.htm")//附件列表中去除邮件正文
                    listAttachments.Nodes.Add(filenm).Tag = att;

            }
        }
    }

    private void listAttachments_AfterSelect(object sender, TreeViewEventArgs e)
    {
        OpenPOP.MIMEParser.Attachment att = (OpenPOP.MIMEParser.Attachment)listAttachments.SelectedNode.Tag;
        OpenPOP.MIMEParser.Message m = (OpenPOP.MIMEParser.Message)msgs["msg" + listView1.SelectedItems[0].Index.ToString()];

        if (att != null & m != null)
        {
            saveFile.FileName = m.GetAttachmentFileName(att);
            DialogResult result = saveFile.ShowDialog();
            if (result != DialogResult.OK)
                return;

            //if (m.IsMIMEMailFile(att))//这里MIME 邮件 也通过附件形式直接下载
            //{
            //    result = MessageBox.Show(this, "邮件附件是 MIME 类型,要执行吗?", "MIME mail", MessageBoxButtons.YesNo);
            //    if (result == DialogResult.Yes)
            //    {
            //        OpenPOP.MIMEParser.Message m2 = att.DecodeAsMessage();
            //        string attachmentNames = "";
            //        bool blnRet = false;
            //        if (m2.AttachmentCount > 0)
            //            for (int i = 0; i < m2.AttachmentCount; i++)
            //            {
            //                OpenPOP.MIMEParser.Attachment att2 = m2.GetAttachment(i);
            //                attachmentNames += m2.GetAttachmentFileName(att2) + "(" + att2.ContentLength + " bytes)rn";
            //            }
            //        blnRet = m.SaveAttachments(System.IO.Path.GetDirectoryName(saveFile.FileName));
            //        MessageBox.Show(this, "附件 " + (blnRet == true ? "保存成功" : "保存失败") + "!rnrn附件:rn" + attachmentNames);
            //    }
            //    else
            //    {
            //        MessageBox.Show(this, "附件 " + ((m.SaveAttachment(att, saveFile.FileName)) ? "保存成功" : "保存失败") + "!");
            //    }
            //}
            //else
            MessageBox.Show(this, "附件 " + ((m.SaveAttachment(att, saveFile.FileName)) ? "保存成功" : "保存失败") + "!");
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        ReceiveMails();
        button2.Enabled = true;
    }

    private void button2_Click(object sender, EventArgs e)
    {
        DialogResult drRet = MessageBox.Show(this, "确定要删除该邮件?", "删除邮件", MessageBoxButtons.YesNo);
        //取出被选中的索引
        ArrayList list1 = new ArrayList();
        int j = 0;
        for (int i = 0; i < this.listView1.CheckedItems.Count; i++)
        {
            if (this.listView1.CheckedItems[i].Checked)
            {
                list1.Add(this.listView1.CheckedItems[i].Index);
                j++;
            }
        }
        int total = this.listView1.Items.Count;
        /*ArrayList list2 = new ArrayList();
        for (int c = 0; c < j;c++ )
        {
            int realindex = total-(int)list1[c];
            list2.Add(realindex);
        }*/
        int realindex = 0;

        if (drRet == DialogResult.Yes)
        {
            for (int c = 0; c < j;c++ )
            {
                realindex = total - (int)list1[c];
                //listView1.Items.RemoveAt((int)list1[c]);
                popClient.DeleteMessage(realindex);
                listView1.Clear();
            }
            //popClient.DeleteMessage(Convert.ToInt32(listMessages.SelectedNode.Tag));
            //listMessages.SelectedNode.Remove();

            drRet = MessageBox.Show(this, "要重新读取邮件列表吗?", "收邮件", MessageBoxButtons.YesNo);
            if (drRet == DialogResult.Yes)
                ReceiveMails();
        }
    }

}

}

解决方案三:

caozhy是对的。
你大概没明白。
你的代码是
inbox类是UserControl的子类。这时,有两个CS文件:1)inbox.cs -- 就是页面上的代码。
2)inbox.designer.cs -- GUI文件,一般默认以图形显示,只要单击编辑框下方的“源代码”或“source”标签,就进入相应的代码。

此时,你就明白了caozhy的回答。

解决方案四:

designer.cs的代码是
namespace mymail
{
partial class Register
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Register));
        this.button1 = new System.Windows.Forms.Button();
        this.username = new System.Windows.Forms.Label();
        this.passwd = new System.Windows.Forms.Label();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.textBox2 = new System.Windows.Forms.TextBox();
        this.label1 = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.linkLabel1 = new System.Windows.Forms.LinkLabel();
        this.label3 = new System.Windows.Forms.Label();
        this.label4 = new System.Windows.Forms.Label();
        this.label5 = new System.Windows.Forms.Label();
        this.SuspendLayout();
        //
        // button1
        //
        this.button1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.button1.Location = new System.Drawing.Point(105, 320);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(125, 30);
        this.button1.TabIndex = 0;
        this.button1.Text = "确 认";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        //
        // username
        //
        this.username.AutoSize = true;
        this.username.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.username.Location = new System.Drawing.Point(71, 74);
        this.username.Name = "username";
        this.username.Size = new System.Drawing.Size(56, 16);
        this.username.TabIndex = 1;
        this.username.Text = "用户名";
        //
        // passwd
        //
        this.passwd.AutoSize = true;
        this.passwd.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.passwd.Location = new System.Drawing.Point(78, 212);
        this.passwd.Name = "passwd";
        this.passwd.Size = new System.Drawing.Size(40, 16);
        this.passwd.TabIndex = 2;
        this.passwd.Text = "密码";
        //
        // textBox1
        //
        this.textBox1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.textBox1.Location = new System.Drawing.Point(149, 71);
        this.textBox1.Name = "textBox1";
        this.textBox1.Size = new System.Drawing.Size(129, 23);
        this.textBox1.TabIndex = 3;
        //
        // textBox2
        //
        this.textBox2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.textBox2.Location = new System.Drawing.Point(149, 211);
        this.textBox2.Name = "textBox2";
        this.textBox2.PasswordChar = '*';
        this.textBox2.Size = new System.Drawing.Size(129, 23);
        this.textBox2.TabIndex = 4;
        //
        // label1
        //
        this.label1.AutoSize = true;
        this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.label1.ForeColor = System.Drawing.SystemColors.Highlight;
        this.label1.Location = new System.Drawing.Point(11, 22);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(259, 14);
        this.label1.TabIndex = 5;
        this.label1.Text = "用户名请使用英文字母、数字(1-20位)";
        //
        // label2
        //
        this.label2.AutoSize = true;
        this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.label2.ForeColor = System.Drawing.SystemColors.Highlight;
        this.label2.Location = new System.Drawing.Point(12, 164);
        this.label2.Name = "label2";
        this.label2.Size = new System.Drawing.Size(245, 14);
        this.label2.TabIndex = 6;
        this.label2.Text = "密码请使用英文字母、数字(1-20位)";
        //
        // linkLabel1
        //
        this.linkLabel1.AutoSize = true;
        this.linkLabel1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
        this.linkLabel1.Location = new System.Drawing.Point(245, 379);
        this.linkLabel1.Name = "linkLabel1";
        this.linkLabel1.Size = new System.Drawing.Size(91, 14);
        this.linkLabel1.TabIndex = 7;
        this.linkLabel1.TabStop = true;
        this.linkLabel1.Text = "返回登录界面";
        this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
        //
        // label3
        //
        this.label3.AutoSize = true;
        this.label3.ForeColor = System.Drawing.Color.Red;
        this.label3.Location = new System.Drawing.Point(152, 103);
        this.label3.Name = "label3";
        this.label3.Size = new System.Drawing.Size(89, 12);
        this.label3.TabIndex = 8;
        this.label3.Text = "不符合约束规则";
        //
        // label4
        //
        this.label4.AutoSize = true;
        this.label4.ForeColor = System.Drawing.Color.Red;
        this.label4.Location = new System.Drawing.Point(152, 243);
        this.label4.Name = "label4";
        this.label4.Size = new System.Drawing.Size(89, 12);
        this.label4.TabIndex = 9;
        this.label4.Text = "不符合约束规则";
        //
        // label5
        //
        this.label5.AutoSize = true;
        this.label5.ForeColor = System.Drawing.Color.Red;
        this.label5.Location = new System.Drawing.Point(154, 103);
        this.label5.Name = "label5";
        this.label5.Size = new System.Drawing.Size(77, 12);
        this.label5.TabIndex = 10;
        this.label5.Text = "用户名已存在";
        //
        // Register
        //
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(340, 411);
        this.Controls.Add(this.label5);
        this.Controls.Add(this.label4);
        this.Controls.Add(this.label3);
        this.Controls.Add(this.linkLabel1);
        this.Controls.Add(this.label2);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.textBox2);
        this.Controls.Add(this.textBox1);
        this.Controls.Add(this.passwd);
        this.Controls.Add(this.username);
        this.Controls.Add(this.button1);
        this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
        this.MaximizeBox = false;
        this.Name = "Register";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "Register";
        this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Register_FormClosing);
        this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Register_FormClosed);
        this.Load += new System.EventHandler(this.Register_Load);
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Label username;
    private System.Windows.Forms.Label passwd;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.TextBox textBox2;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.LinkLabel linkLabel1;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.Label label5;
}

}

解决方案五:

上面那个是另一register.designer.cs是有用的,我的inbox.designer.cs却没有用
inbox.designer.cs
namespace mymail
{
partial class inbox
{
///
/// 必需的设计器变量。
///
private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region 组件设计器生成的代码

    /// <summary>
    /// 设计器支持所需的方法 - 不要
    /// 使用代码编辑器修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
        this.saveFile = new System.Windows.Forms.SaveFileDialog();
        this.listView1 = new System.Windows.Forms.ListView();
        this.webBrowser1 = new System.Windows.Forms.WebBrowser();
        this.listAttachments = new System.Windows.Forms.TreeView();
        this.button1 = new System.Windows.Forms.Button();
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.groupBox2 = new System.Windows.Forms.GroupBox();
        this.button2 = new System.Windows.Forms.Button();
        this.button3 = new System.Windows.Forms.Button();
        this.SuspendLayout();
        //
        // saveFile
        //
        this.saveFile.Title = "Save Attachment";
        //
        // listView1
        //
        this.listView1.Activation = System.Windows.Forms.ItemActivation.OneClick;
        this.listView1.CheckBoxes = true;
        this.listView1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.listView1.HotTracking = true;
        this.listView1.HoverSelection = true;
        this.listView1.Location = new System.Drawing.Point(3, 31);
        this.listView1.Name = "listView1";
        this.listView1.Size = new System.Drawing.Size(307, 489);
        this.listView1.TabIndex = 0;
        this.listView1.UseCompatibleStateImageBehavior = false;
        this.listView1.View = System.Windows.Forms.View.List;
        this.listView1.ItemActivate += new System.EventHandler(this.listView1_ItemActivate);
        this.listView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseDoubleClick);
        //
        // webBrowser1
        //
        this.webBrowser1.Location = new System.Drawing.Point(316, 31);
        this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
        this.webBrowser1.Name = "webBrowser1";
        this.webBrowser1.Size = new System.Drawing.Size(672, 390);
        this.webBrowser1.TabIndex = 1;
        //
        // listAttachments
        //
        this.listAttachments.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.listAttachments.Location = new System.Drawing.Point(316, 443);
        this.listAttachments.Name = "listAttachments";
        this.listAttachments.Size = new System.Drawing.Size(659, 76);
        this.listAttachments.TabIndex = 2;
        this.listAttachments.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.listAttachments_AfterSelect);
        //
        // button1
        //
        this.button1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.button1.Location = new System.Drawing.Point(21, 4);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 3;
        this.button1.Text = "删除";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        //
        // groupBox1
        //
        this.groupBox1.Location = new System.Drawing.Point(316, 424);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(672, 93);
        this.groupBox1.TabIndex = 4;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "附件";
        //
        // groupBox2
        //
        this.groupBox2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.groupBox2.Location = new System.Drawing.Point(315, 13);
        this.groupBox2.Name = "groupBox2";
        this.groupBox2.Size = new System.Drawing.Size(675, 512);
        this.groupBox2.TabIndex = 5;
        this.groupBox2.TabStop = false;
        this.groupBox2.Text = "正文";
        //
        // button2
        //
        this.button2.Enabled = false;
        this.button2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.button2.Location = new System.Drawing.Point(121, 4);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(75, 23);
        this.button2.TabIndex = 6;
        this.button2.Text = "回复";
        this.button2.UseVisualStyleBackColor = true;
        this.button2.Click += new System.EventHandler(this.button2_Click);
        //
        // button3
        //
        this.button3.Enabled = false;
        this.button3.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
        this.button3.Location = new System.Drawing.Point(218, 4);
        this.button3.Name = "button3";
        this.button3.Size = new System.Drawing.Size(75, 23);
        this.button3.TabIndex = 7;
        this.button3.Text = "转发";
        this.button3.UseVisualStyleBackColor = true;
        //
        // inbox
        //
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.Color.White;
        this.Controls.Add(this.button3);
        this.Controls.Add(this.button2);
        this.Controls.Add(this.button1);
        this.Controls.Add(this.listAttachments);
        this.Controls.Add(this.webBrowser1);
        this.Controls.Add(this.listView1);
        this.Controls.Add(this.groupBox1);
        this.Controls.Add(this.groupBox2);
        this.Name = "inbox";
        this.Size = new System.Drawing.Size(991, 525);
        this.Load += new System.EventHandler(this.inbox_Load);
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.SaveFileDialog saveFile;
    private System.Windows.Forms.ListView listView1;
    private System.Windows.Forms.WebBrowser webBrowser1;
    private System.Windows.Forms.TreeView listAttachments;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.GroupBox groupBox2;
    private System.Windows.Forms.Button button2;
    private System.Windows.Forms.Button button3;

}

}

时间: 2024-10-27 06:00:49

C# 用户控件的Load事件不能执行的相关文章

有什么办法让用户控件中的事件先执行呢。在page_load里面是后执行用户控件里的时间的。(在线望各位兄台帮忙)

问题描述 我在用户控件中放了一个dropdownlist,想选不同的项datagrid显示不同的内容,可dropdownlist的值不知如何传不过来.望各位兄台指点 解决方案 解决方案二:bubbleeventinusercontrol解决方案三:xiahouwen兄,都是英文啊.呵呵.有没有中文方面的.解决方案四:在用户控件控件中放置一个方法,比如publicvoidInitControls();在这个方法中绑定dropdownlist,返回选择的值,或者用属性返回在ASPX页面的page_l

ASP.NET开发系列之在用户控件中添加事件

asp.net|控件 在<在用户控件中添加属性>这一篇文章中我们演示了如何在用户控件中添加属性,接下来我们演示如何在用户控件中添加事件. 在<在用户控件中添加属性>这一篇文章中我们定义了一个用户登录的用户控件UserLogin.ascx 文件,里面包含了一个LinkButton服务器按钮控件,当用户单击该按钮时服务器端会自动生成一个回发来激发Page.Load事件.除了服务器自动产生回发来激发Page.Load事件外,我们可以给LinkButton添加一个它自己的事件,添加事件其实

自定义事件异步响应-自定义用户控件中,事件的异步响就

问题描述 自定义用户控件中,事件的异步响就 自定义一含有自定义事件的用户控件,当在异步情况下时,该事件的处理程序总是为null,怎么处理? 解决方案 对应事件的实例是否还有效.存在. 解决方案二: 什么叫事件的处理程序总是为null,仔细调试下,事件处理程序有没有传正确,应该同步等加载完了再执行.

用户控件中的事件捕捉问题

问题描述 描述:工程中有frmForm1,frmBaseForm窗口,UCButton用户控件.frmForm1继承自frmBaseForm窗口.单击用户控件中的按钮时会触发ButtonClick事件,在frmBaseForm窗口中捕捉ButtonClick到事件时关闭当前窗口,在frmForm1窗口中捕捉ButtonClick到事件时会弹一个对话框.代码:'''''''''''''''''''''''''''''''''''''''''''''''''''''''''UCButton用户控件P

WinForm 用户控件使用——设置用户控件的按钮事件

项目中需要对一个DataGridView控件进行类似于Excel查找的功能,之前是使用的DevExpress里面的DataGrid,用起来倒是很方便,它的列头可以和Excel一样进行随意的筛选,但是那个是收费的东东,我用了几天破解版的,担心以后会有影响所以还是决定换掉它,VS自带的DataGridView跟DevExpress里面的DataGrid相比确实相差太远了,样式不好看不说,功能上也欠缺了很多,为了满足用户的需求只得做一个查找定位的功能出来勉强满足一下用户的需求, 1 using Sys

动态加载用户控件,用户控件里面的事件不能用。在线(望各位高手帮忙)

问题描述 加载代码如下:privatevoidconn(){stringaa=Request.QueryString["num"].ToString();stringsql="selectmodelnumberfromplate_discards_detailswherenumbers='"+Request.QueryString["num"]+"'";DbConncon=newDbConn();OleDbConnection

ASP.NET用户控件说明和添加事件

在WEB开发中经常有一些代码是在很多地方重复出现的,象导航栏.用户登录/注册和首页上面的一些固定栏目等.这些可重用的代码我们可以把它写成一个通用模块供需要的地方来引用,这样做即节省了开发时间还方便以后的维护. 在ASP.NET的web编程中提供了一种叫做"用户控件"可以帮助我们完成这种做法,其文件扩展名是".ascx",由于ascx文件是用来插入ASPX页面中使用的,而一个ASPX窗体只能包含一个<form>标志,所以ascx用户控件不能包含<fo

用户控件中子控件的事件在外部如何改变?

问题描述 各位大虾,请问,用户控件中子控件的事件在外部如何改变?现在要做一个通用的用户控件,比如一棵树放在面板里面.其他模块调用这个用户控件,但是不同模块中,对树控件的点击处理不同(假如业务处理代码很多,足够多,不能通过传递参数等手段解决),而在外部,给用户控件添加事件处理函数时貌似不能再改变数的事件处理函数了,只能编辑用户控件本身的事件函数.这样就导致用户控件并不通用..不知道是否可以做到在外部改变用户控件子控件事件?本人接触c#时间短,请各位指教! 解决方案 解决方案二:1.把自定义控件内的

请问,C#如何在用户控件切换时将timer关掉?

问题描述 请问,C#如何在用户控件切换时将timer关掉? 解决方案 解决方案二:什么叫用户控件切换?tabControl?timer又是在哪里?解决方案三:在用户控件的显示隐藏中控制解决方案四:timer1.enabled=true/false;解决方案五:privatevoidbtnAuto_Click(objectsender,EventArgse){w1.Show();gpbWindows.Controls.Clear();gpbWindows.Controls.Add(w1);}我的用