📄 sendmailform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net ;
using System.Net .Sockets ;
using MailSend;
using System.Data ;
using System.Runtime .InteropServices ;
namespace MailManageSystem
{
/// <summary>
/// Send 的摘要说明。
/// </summary>
public class SendMailForm : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.OpenFileDialog openFileDialog1;//语言编码
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton tbSend;
private System.Windows.Forms.ToolBarButton tbSave;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton tbAttachment;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.ImageList imlSendMail;
private System.Windows.Forms.ImageList imlAttachment;
private System.Windows.Forms.ContextMenu conAttachment;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.MenuItem menuItem15;
private System.Windows.Forms.MenuItem menuItem16;
private System.Windows.Forms.MenuItem menuItem17;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox txtTo;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtSubject;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.RichTextBox txtMessage;
private ArrayList array=new ArrayList ();
private System.Windows.Forms.ListView ltAttachment;
private System.Windows.Forms.ComboBox cbHtml;
int i = 0;
//EntryPoint 给出Dll入口点的名称,如果没有给出,则用方法本身的名称。
[DllImport("shell32.dll",EntryPoint="ShellExecute")]
private static extern int ShellExecute(IntPtr hwnd, string lpOperation,string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
//函数SHGetFileInfo()的返回值也随uFlags的取值变化而有所不同。
//通过调用SHGetFileInfo()可以由psfi参数得到文件的图标句柄,但要注意在uFlags参数中不使用SHGFI_PIDL时,SHGetFileInfo()不能获得"我的电脑"等虚似文件夹的信息。
[DllImport("Shell32.dll")]
private static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, SHGFI uFlags);
[StructLayout(LayoutKind.Sequential)]
private struct SHFILEINFO
{
//重载一个构造函数
public SHFILEINFO(bool b)
{
hIcon = IntPtr.Zero ; iIcon = 0; dwAttributes = 0; szDisplayName = ""; szTypeName = "";
}
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.LPStr, SizeConst =256)]
public string szDisplayName;
[MarshalAs(UnmanagedType.LPStr, SizeConst = 80)]
public string szTypeName;
};
//图标类型的结构体
private enum SHGFI
{
SHGFI_ICON =0x000000100, // get icon
SHGFI_DISPLAYNAME =0x000000200, // get display name
SHGFI_TYPENAME =0x000000400, // get type name
SHGFI_ATTRIBUTES =0x000000800, // get attributes
SHGFI_ICONLOCATION =0x000001000, // get icon location
SHGFI_EXETYPE =0x000002000, // return exe type
SHGFI_SYSICONINDEX =0x000004000, // get system icon index
SHGFI_LINKOVERLAY =0x000008000, // put a link overlay on icon
SHGFI_SELECTED =0x000010000, // show icon in selected state
SHGFI_ATTR_SPECIFIED =0x000020000, // get only specified attributes
SHGFI_LARGEICON =0x000000000, // get large icon
SHGFI_SMALLICON =0x000000001, // get small icon
SHGFI_OPENICON =0x000000002, // get open icon
SHGFI_SHELLICONSIZE =0x000000004, // get shell size icon
SHGFI_PIDL =0x000000008, // pszPath is a pidl
SHGFI_USEFILEATTRIBUTES =0x000000010, // use passed dwFileAttribute
SHGFI_ADDOVERLAYS =0x000000020, // apply the appropriate overlays
SHGFI_OVERLAYINDEX =0x000000040 // Get the index of the overlay
}
/// <summary>
/// 调用获的程序图标句柄的函数
/// </summary>
/// <param name="strPath">选定程序的绝对路径</param>
/// <returns></returns>
private static Icon GetIcon(string strPath)
{
try
{
SHFILEINFO info = new SHFILEINFO();
int cbFileInfo = Marshal.SizeOf(info);
SHGFI flags;
flags = SHGFI.SHGFI_ICON|SHGFI.SHGFI_LARGEICON|SHGFI.SHGFI_ATTRIBUTES|SHGFI.SHGFI_EXETYPE;
SHGetFileInfo(strPath, 32|0, ref info,(uint)cbFileInfo,flags);
return Icon.FromHandle(info.hIcon);
}
catch(Exception ex)
{
MessageBox.Show (ex.ToString ());
return null;
}
}
public SendMailForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SendMailForm));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.tbSend = new System.Windows.Forms.ToolBarButton();
this.tbSave = new System.Windows.Forms.ToolBarButton();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.tbAttachment = new System.Windows.Forms.ToolBarButton();
this.imlSendMail = new System.Windows.Forms.ImageList(this.components);
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.imlAttachment = new System.Windows.Forms.ImageList(this.components);
this.conAttachment = new System.Windows.Forms.ContextMenu();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuItem13 = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem15 = new System.Windows.Forms.MenuItem();
this.menuItem17 = new System.Windows.Forms.MenuItem();
this.menuItem16 = new System.Windows.Forms.MenuItem();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.cbHtml = new System.Windows.Forms.ComboBox();
this.txtTo = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtSubject = new System.Windows.Forms.TextBox();
this.ltAttachment = new System.Windows.Forms.ListView();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel1 = new System.Windows.Forms.Panel();
this.txtMessage = new System.Windows.Forms.RichTextBox();
this.groupBox2.SuspendLayout();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem5,
this.menuItem6});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem8,
this.menuItem4});
this.menuItem1.Text = "邮件(M)";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "立即发送";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "草稿";
//
// menuItem8
//
this.menuItem8.Index = 2;
this.menuItem8.Text = "-";
//
// menuItem4
//
this.menuItem4.Index = 3;
this.menuItem4.Text = "退出";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Index = 1;
this.menuItem5.Text = "";
//
// menuItem6
//
this.menuItem6.Index = 2;
this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem7});
this.menuItem6.Text = "插入(I)";
//
// menuItem7
//
this.menuItem7.Index = 0;
this.menuItem7.Text = "增加附件";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// toolBar1
//
this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.tbSend,
this.tbSave,
this.toolBarButton1,
this.tbAttachment});
this.toolBar1.ButtonSize = new System.Drawing.Size(100, 80);
this.toolBar1.DropDownArrows = true;
this.toolBar1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.toolBar1.ImageList = this.imlSendMail;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(800, 41);
this.toolBar1.TabIndex = 3;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// tbSend
//
this.tbSend.ImageIndex = 0;
this.tbSend.Text = "发送";
//
// tbSave
//
this.tbSave.ImageIndex = 1;
this.tbSave.Text = "保存";
//
// toolBarButton1
//
this.toolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// tbAttachment
//
this.tbAttachment.ImageIndex = 2;
this.tbAttachment.Text = "附件";
//
// imlSendMail
//
this.imlSendMail.ImageSize = new System.Drawing.Size(16, 16);
this.imlSendMail.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imlSendMail.ImageStream")));
this.imlSendMail.TransparentColor = System.Drawing.Color.Transparent;
//
// imlAttachment
//
this.imlAttachment.ImageSize = new System.Drawing.Size(16, 16);
this.imlAttachment.TransparentColor = System.Drawing.Color.Transparent;
//
// conAttachment
//
this.conAttachment.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem9,
this.menuItem10,
this.menuItem11,
this.menuItem12,
this.menuItem13,
this.menuItem14});
//
// menuItem9
//
this.menuItem9.Index = 0;
this.menuItem9.Shortcut = System.Windows.Forms.Shortcut.Alt0;
this.menuItem9.Text = "增加(A)...";
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click_1);
//
// menuItem10
//
this.menuItem10.Index = 1;
this.menuItem10.Shortcut = System.Windows.Forms.Shortcut.Alt1;
this.menuItem10.Text = "删除(D)...";
this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
//
// menuItem11
//
this.menuItem11.Index = 2;
this.menuItem11.Text = "-";
//
// menuItem12
//
this.menuItem12.Index = 3;
this.menuItem12.Shortcut = System.Windows.Forms.Shortcut.Alt2;
this.menuItem12.Text = "打开(O)...";
this.menuItem12.Click += new System.EventHandler(this.menuItem12_Click);
//
// menuItem13
//
this.menuItem13.Index = 4;
this.menuItem13.Text = "-";
//
// menuItem14
//
this.menuItem14.Index = 5;
this.menuItem14.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem15,
this.menuItem17,
this.menuItem16});
this.menuItem14.Text = "排列图标(V)...";
//
// menuItem15
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -