Click here to Skip to main content
15,891,184 members
Articles / Programming Languages / C#

SMTP and POP3 Mail Server

Rate me:
Please Sign up or sign in to vote.
4.88/5 (96 votes)
29 Sep 20031 min read 1M   18.9K   315  
An SMTP and POP3 mail server written using the .NET Framework and C#.
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace LumiSoft.UI.Controls
{
	/// <summary>
	/// Button control.
	/// </summary>
	[DefaultEvent("ButtonPressed"),]
	public class WButton : WFocusedCtrlBase
	{		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		/// <summary>
		/// Occurs when the button is pressed.
		/// </summary>
		public event ButtonPressedEventHandler ButtonPressed = null;

		private string m_Text   = ""; // Holds property 'Text'.
		private string m_TextID = "";

		/// <summary>
		/// Default constructor.
		/// </summary>
		public WButton()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitForm call
		}

		#region function Dispose

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#endregion

		#region Component 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()
		{
			// 
			// WButton
			// 
			this.Name = "WButton";
			this.Size = new System.Drawing.Size(80, 24);

		}
		#endregion


		#region function DrawControl

		/// <summary>
		/// 
		/// </summary>
		/// <param name="g"></param>
		/// <param name="hot"></param>
		protected override void DrawControl(Graphics g,bool hot)
		{	
			DrawControl(g,hot,false);
		}

		private void DrawControl(Graphics g,bool hot,bool pressed)
		{
			g.Clear(m_ViewStyle.GetButtonColor(hot,pressed));
			g.DrawRectangle(new Pen(m_ViewStyle.GetBorderColor(hot),2),this.ClientRectangle);

			StringFormat format  = new StringFormat();
			format.LineAlignment = StringAlignment.Center;
			format.Alignment     = StringAlignment.Center;

			Rectangle txtRect = this.ClientRectangle;
			if(pressed){
				txtRect.Location = new Point(txtRect.Left+1,txtRect.Top+1);
			}

			if(this.Enabled){
				g.DrawString(m_Text,this.Font,new SolidBrush(Color.Black),txtRect,format);
			}
			else{
				g.DrawString(m_Text,this.Font,new SolidBrush(Color.FromArgb(128,128,128)),txtRect,format);
			}
		}

		#endregion


		#region override OnMouseDown

		/// <summary>
		/// 
		/// </summary>
		/// <param name="e"></param>
		protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
		{
			base.OnMouseDown(e);

			if(this.Enabled && this.Focused){
				using(Graphics g = this.CreateGraphics()){
					DrawControl(g,true,true);
				}
			}
		}

		#endregion

		#region override OnMouseUp

		/// <summary>
		/// 
		/// </summary>
		/// <param name="e"></param>
		protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
		{
			base.OnMouseUp(e);

			if(this.Enabled && this.Focused && this.IsMouseInControl){
				using(Graphics g = this.CreateGraphics()){
					DrawControl(g,this.Focused,false);
				}

				OnButtonClicked();
			}
			else{
				this.Invalidate(false);
			}
		}

		#endregion

		#region override OnKeyDown

		/// <summary>
		/// 
		/// </summary>
		/// <param name="e"></param>
		protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
		{
			base.OnKeyDown(e);

			if(this.Enabled && (e.KeyData == Keys.Space || e.KeyData == Keys.Enter)){
				using(Graphics g = this.CreateGraphics()){
					DrawControl(g,true,true);
				}

				// Enter gives immedeate click
				if(e.KeyData == Keys.Enter){
					OnButtonClicked();
				}
			}
		}

		#endregion

		#region override OnKeyUp

		/// <summary>
		/// 
		/// </summary>
		/// <param name="e"></param>
		protected override void OnKeyUp(System.Windows.Forms.KeyEventArgs e)
		{
			base.OnKeyUp(e);

			if(this.Enabled && (e.KeyData == Keys.Space || e.KeyData == Keys.Enter)){				
				using(Graphics g = this.CreateGraphics()){
					DrawControl(g,this.Focused,false);
				}			

				if(e.KeyData == Keys.Space){
					OnButtonClicked();
				}
			}
		}

		#endregion


		#region function ShouldSerialize
		
		/// <summary>
		/// 
		/// </summary>
		/// <param name="propertyName"></param>
		/// <returns></returns>
		public override bool ShouldSerialize(string propertyName)
		{
			bool retVal = true;

			switch(propertyName)
			{
				case "TextID":
					if(this.TextID.Length == 0){
						retVal = false;
					}
					break;

				case "UseStaticViewStyle":
					if(this.UseStaticViewStyle == false){ //**
						retVal = false;
					}
					break;

				case "Size":
					if(this.Size.Equals(new System.Drawing.Size(80, 24))){
						retVal = false;
					}
					break;
			}

			return retVal;
		}

		#endregion
        

		#region Properties Implementation

		/// <summary>
		/// Gets or sets button caption.
		/// </summary>
		[
		Browsable(true),
		DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)
		]
		public override string Text
		{
			get{ return m_Text; }

			set{ 
				m_Text = value; 
				this.Invalidate();
			}
		}

		/// <summary>
		/// Gets or sets text ID. This is for multilingual support.
		/// For examle at runtime you can search with this textID right caption for item.
		/// </summary>
		public string TextID
		{
			get{ return m_TextID; }

			set{ m_TextID = value;	}
		}

		#endregion

		#region Events Implementation

		#region function OnButtonClicked

		/// <summary>
		/// 
		/// </summary>
		protected void OnButtonClicked()
		{
			if(this.ButtonPressed != null){
				this.ButtonPressed(this,new System.EventArgs());
			}
		}

		#endregion

		#endregion

	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Estonia Estonia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions