u013066730
mjiansun
采纳率50%
2015-05-10 15:02

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

10
已采纳

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();
    }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • caozhy 从今以后生命中的每一秒都属于我爱的人 6年前

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

    点赞 3 评论 复制链接分享
  • u013066730 mjiansun 6年前

    上面那个是另一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;
    
    }
    

    }

    点赞 评论 复制链接分享
  • u013066730 mjiansun 6年前

    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;
    }
    

    }

    点赞 评论 复制链接分享
  • frank_20080215 frank_20080215 6年前

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

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

    点赞 评论 复制链接分享
  • u013066730 mjiansun 6年前

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

    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)\r\n";
                //            }
                //        blnRet = m.SaveAttachments(System.IO.Path.GetDirectoryName(saveFile.FileName));
                //        MessageBox.Show(this, "附件 " + (blnRet == true ? "保存成功" : "保存失败") + "!\r\n\r\n附件:\r\n" + 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();
            }
        }
    
    }
    

    }

    点赞 评论 复制链接分享

相关推荐