Click here to Skip to main content
15,897,315 members
Articles / Mobile Apps

ForestPad - a method for storing and retrieving textual information

Rate me:
Please Sign up or sign in to vote.
3.85/5 (14 votes)
6 Jun 2004CPOL11 min read 131.4K   404   30  
Three applications: PocketPC, Windows Desktop, and a Web Service collaborate to syncronize your textual information
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Web.Mail;

namespace ForestPadDesktop
{
	/// <summary>
	/// Summary description for EmailText.
	/// </summary>
	public class EmailText : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox textBoxTextToEmail;
		private System.Windows.Forms.TextBox textBoxSubject;
		private System.Windows.Forms.Label labelTo;
		private System.Windows.Forms.Label labelBcc;
		private System.Windows.Forms.Label labelSubject;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBoxBcc;
		private System.Windows.Forms.TextBox textBoxCc;
		private System.Windows.Forms.TextBox textBoxTo;
		private System.Windows.Forms.Button buttonSend;
		private System.Windows.Forms.Button buttonCancel;
		private string smtpServerName;
		private string fromAddress;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public EmailText(string SmtpServerName, string FromAddress)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			smtpServerName = SmtpServerName;
			fromAddress = FromAddress;

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(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()
		{
			this.textBoxTextToEmail = new System.Windows.Forms.TextBox();
			this.textBoxSubject = new System.Windows.Forms.TextBox();
			this.textBoxBcc = new System.Windows.Forms.TextBox();
			this.textBoxCc = new System.Windows.Forms.TextBox();
			this.textBoxTo = new System.Windows.Forms.TextBox();
			this.labelTo = new System.Windows.Forms.Label();
			this.labelBcc = new System.Windows.Forms.Label();
			this.labelSubject = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.buttonSend = new System.Windows.Forms.Button();
			this.buttonCancel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// textBoxTextToEmail
			// 
			this.textBoxTextToEmail.Location = new System.Drawing.Point(8, 144);
			this.textBoxTextToEmail.Multiline = true;
			this.textBoxTextToEmail.Name = "textBoxTextToEmail";
			this.textBoxTextToEmail.ScrollBars = System.Windows.Forms.ScrollBars.Both;
			this.textBoxTextToEmail.Size = new System.Drawing.Size(400, 232);
			this.textBoxTextToEmail.TabIndex = 4;
			this.textBoxTextToEmail.Text = "";
			this.textBoxTextToEmail.WordWrap = false;
			// 
			// textBoxSubject
			// 
			this.textBoxSubject.Location = new System.Drawing.Point(56, 112);
			this.textBoxSubject.Name = "textBoxSubject";
			this.textBoxSubject.Size = new System.Drawing.Size(352, 20);
			this.textBoxSubject.TabIndex = 3;
			this.textBoxSubject.Text = "";
			// 
			// textBoxBcc
			// 
			this.textBoxBcc.Location = new System.Drawing.Point(56, 88);
			this.textBoxBcc.Name = "textBoxBcc";
			this.textBoxBcc.Size = new System.Drawing.Size(352, 20);
			this.textBoxBcc.TabIndex = 2;
			this.textBoxBcc.Text = "";
			// 
			// textBoxCc
			// 
			this.textBoxCc.Location = new System.Drawing.Point(56, 64);
			this.textBoxCc.Name = "textBoxCc";
			this.textBoxCc.Size = new System.Drawing.Size(352, 20);
			this.textBoxCc.TabIndex = 1;
			this.textBoxCc.Text = "";
			// 
			// textBoxTo
			// 
			this.textBoxTo.Location = new System.Drawing.Point(56, 40);
			this.textBoxTo.Name = "textBoxTo";
			this.textBoxTo.Size = new System.Drawing.Size(352, 20);
			this.textBoxTo.TabIndex = 0;
			this.textBoxTo.Text = "";
			// 
			// labelTo
			// 
			this.labelTo.Location = new System.Drawing.Point(8, 40);
			this.labelTo.Name = "labelTo";
			this.labelTo.TabIndex = 6;
			this.labelTo.Text = "To:";
			// 
			// labelBcc
			// 
			this.labelBcc.Location = new System.Drawing.Point(8, 88);
			this.labelBcc.Name = "labelBcc";
			this.labelBcc.Size = new System.Drawing.Size(96, 23);
			this.labelBcc.TabIndex = 7;
			this.labelBcc.Text = "Bcc:";
			// 
			// labelSubject
			// 
			this.labelSubject.Location = new System.Drawing.Point(8, 112);
			this.labelSubject.Name = "labelSubject";
			this.labelSubject.TabIndex = 8;
			this.labelSubject.Text = "Subject:";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 64);
			this.label1.Name = "label1";
			this.label1.TabIndex = 9;
			this.label1.Text = "Cc:";
			// 
			// buttonSend
			// 
			this.buttonSend.Location = new System.Drawing.Point(8, 8);
			this.buttonSend.Name = "buttonSend";
			this.buttonSend.Size = new System.Drawing.Size(80, 24);
			this.buttonSend.TabIndex = 5;
			this.buttonSend.Text = "Send";
			this.buttonSend.Click += new System.EventHandler(this.buttonSend_Click);
			// 
			// buttonCancel
			// 
			this.buttonCancel.Location = new System.Drawing.Point(328, 384);
			this.buttonCancel.Name = "buttonCancel";
			this.buttonCancel.Size = new System.Drawing.Size(80, 23);
			this.buttonCancel.TabIndex = 6;
			this.buttonCancel.Text = "Cancel";
			this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
			// 
			// EmailText
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(416, 410);
			this.Controls.Add(this.buttonCancel);
			this.Controls.Add(this.buttonSend);
			this.Controls.Add(this.textBoxTo);
			this.Controls.Add(this.textBoxCc);
			this.Controls.Add(this.textBoxBcc);
			this.Controls.Add(this.textBoxSubject);
			this.Controls.Add(this.textBoxTextToEmail);
			this.Controls.Add(this.labelTo);
			this.Controls.Add(this.labelBcc);
			this.Controls.Add(this.labelSubject);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "EmailText";
			this.ResumeLayout(false);

		}
		#endregion

		private void buttonSend_Click(object sender, System.EventArgs e)
		{
			try
			{
				MailMessage message = new MailMessage();
				message.To = textBoxTo.Text;
				message.From = fromAddress;
				message.Cc = textBoxCc.Text;
				message.Bcc = textBoxBcc.Text;
				message.Subject = textBoxSubject.Text;
				message.Body = textBoxTextToEmail.Text;
            
				SmtpMail.SmtpServer = smtpServerName;
				SmtpMail.Send(message);
			}
			catch(Exception ex)
			{
				MessageBox.Show("Problem sending email: " + ex.ToString());
			}
			finally
			{
				this.Close();
			}
		}

		public void SetText(string Text)
		{
			textBoxTextToEmail.Text = Text;
			textBoxTextToEmail.Refresh();
		}

		private void buttonCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Snoffleware Studios LLC
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions