Number to Word Operation


using System;
namespace NumnerOperation
{
    public class NumberToEnglish
    {
        public String changeNumericToWords(double numb)
        {
            String num = numb.ToString();
            return changeToWords(num, false);
        }
        public String changeCurrencyToWords(String numb)
        {
            return changeToWords(numb, true);
        }
        public String changeNumericToWords(String numb)
        {
            return changeToWords(numb, false);
        }
        public String changeCurrencyToWords(double numb)
        {
            return changeToWords(numb.ToString(), true);
        }
        private String changeToWords(String numb, bool isCurrency)
        {
            String val = "", wholeNo = numb, points = "", andStr = "", pointStr = "";
            String endStr = (isCurrency) ? ("Only") : ("");
            try
            {
                int decimalPlace = numb.IndexOf(".");
                if (decimalPlace > 0)
                {
                    wholeNo = numb.Substring(0, decimalPlace);
                    points = numb.Substring(decimalPlace + 1);
                    if (Convert.ToInt32(points) > 0)
                    {
                        andStr = (isCurrency) ? ("and") : ("point");// just to separate whole numbers from points/cents
                        //endStr = (isCurrency) ? ("Cents " + endStr) : ("");
                        endStr = (isCurrency) ? ("Paisa " + endStr) : ("");
                        pointStr = translateCents(points);
                    }
                }
                val = String.Format("{0} {1}{2} {3}", translateWholeNumber(wholeNo).Trim(), andStr, pointStr, endStr);
            }
            catch { ;}
            return val;
        }
        private String translateWholeNumber(String number)
        {
            string word = "";
            try
            {
                bool beginsZero = false;//tests for 0XX
                bool isDone = false;//test if already translated
                double dblAmt = (Convert.ToDouble(number));
                //if ((dblAmt > 0) && number.StartsWith("0"))
                if (dblAmt > 0)
                {//test for zero or digit zero in a nuemric
                    beginsZero = number.StartsWith("0");

                    int numDigits = number.Length;
                    int pos = 0;//store digit grouping
                    String place = "";//digit grouping name:hundres,thousand,etc...
                    switch (numDigits)
                    {
                        case 1://ones' range
                            word = ones(number);
                            isDone = true;
                            break;
                        case 2://tens' range
                            word = tens(number);
                            isDone = true;
                            break;
                        case 3://hundreds' range
                            pos = (numDigits % 3) + 1;
                            place = " Hundred ";
                            break;
                        case 4://thousands' range
                        case 5:
                        case 6:
                            pos = (numDigits % 4) + 1;
                            place = " Thousand ";
                            break;
                        case 7://millions' range
                        case 8:
                        case 9:
                            pos = (numDigits % 7) + 1;
                            place = " Million ";
                            break;
                        case 10://Billions's range
                            pos = (numDigits % 10) + 1;
                            place = " Billion ";
                            break;
                        //add extra case options for anything above Billion...
                        default:
                            isDone = true;
                            break;
                    }
                    if (!isDone)
                    {//if transalation is not done, continue...(Recursion comes in now!!)
                        word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos));
                        //check for trailing zeros
                        if (beginsZero) word = " and " + word.Trim();
                    }
                    //ignore digit grouping names
                    if (word.Trim().Equals(place.Trim())) word = "";
                }
            }
            catch { ;}
            return word.Trim();
        }
        private String tens(String digit)
        {
            int digt = Convert.ToInt32(digit);
            String name = null;
            switch (digt)
            {
                case 10:
                    name = "Ten";
                    break;
                case 11:
                    name = "Eleven";
                    break;
                case 12:
                    name = "Twelve";
                    break;
                case 13:
                    name = "Thirteen";
                    break;
                case 14:
                    name = "Fourteen";
                    break;
                case 15:
                    name = "Fifteen";
                    break;
                case 16:
                    name = "Sixteen";
                    break;
                case 17:
                    name = "Seventeen";
                    break;
                case 18:
                    name = "Eighteen";
                    break;
                case 19:
                    name = "Nineteen";
                    break;
                case 20:
                    name = "Twenty";
                    break;
                case 30:
                    name = "Thirty";
                    break;
                case 40:
                    name = "Fourty";
                    break;
                case 50:
                    name = "Fifty";
                    break;
                case 60:
                    name = "Sixty";
                    break;
                case 70:
                    name = "Seventy";
                    break;
                case 80:
                    name = "Eighty";
                    break;
                case 90:
                    name = "Ninety";
                    break;
                default:
                    if (digt > 0)
                    {
                        name = tens(digit.Substring(0, 1) + "0") + " " + ones(digit.Substring(1));
                    }
                    break;
            }
            return name;
        }
        private String ones(String digit)
        {
            int digt = Convert.ToInt32(digit);
            String name = "";
            switch (digt)
            {
                case 1:
                    name = "One";
                    break;
                case 2:
                    name = "Two";
                    break;
                case 3:
                    name = "Three";
                    break;
                case 4:
                    name = "Four";
                    break;
                case 5:
                    name = "Five";
                    break;
                case 6:
                    name = "Six";
                    break;
                case 7:
                    name = "Seven";
                    break;
                case 8:
                    name = "Eight";
                    break;
                case 9:
                    name = "Nine";
                    break;
            }
            return name;
        }
        private String translateCents(String cents)
        {
            String cts = "", digit = "", engOne = "";
            for (int i = 0; i < cents.Length; i++)
            {
                digit = cents[i].ToString();
                if (digit.Equals("0"))
                {
                    engOne = "Zero";
                }
                else
                {
                    engOne = ones(digit);
                }
                cts += " " + engOne;
            }
            return cts;
        }
    }
}

Connection string for OLEDB(Access Database)


Using System.Data.OleDb;

public class OleDbMeConnection
    {
        OleDbConnection con = new OleDbConnection();

        public OleDbConnection OpenConnnection()
        {
            try
            {
                con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=temp.mdb; Jet OLEDB:Database Password=mypassword";
                return con;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }

Connection string for MYSQL



using MySql.Data.MySqlClient;

 public MySqlActivity(string DatabaseName)
            {
                ConnectionString = "Data Source=localhost;Database=" + DatabaseName + ";    UserId=root;Password=; charset='utf8'";
            }

            public MySqlActivity(string DatabaseServer, string DatabaseName)
            {
                ConnectionString = "Data Source=" + DatabaseServer + ";Database=" + DatabaseName + "; UserId=root;Password=";
            }

            public MySqlActivity(string DatabaseServer, string DatabaseName, string UserId, string Password)
            {
                ConnectionString = "Data Source=" + DatabaseServer + ";Database=" + DatabaseName + "; UserId=" + UserId + ";Password=" + Password + "";
            }

Sql serve connection string


using System.Data.SqlClient;

  public SqlServerActiviteis(string DBSourcePath)
            {
                con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + DBSourcePath + "; Integrated Security=True;User Instance=True";
            }

Open database connection


con.Open();
/*Where Open() is a Connection Class Method which open connection by connection string*/

Insert data into database


private Boolean CreateCommand(string Query)
{
       try
       {
             /*con is a object of Connection Class*/
             OleDbCommand com = new OleDbCommand();
             //or
             MySqlCommand com = new MySqlCommand();
             //or
             SqlCommand com = new SqlCommand();

             com.Connection = con;
             com.CommandText = Query;
             com.ExecuteNonQuery();
             return com;
        }    
        catch (Exception ex)
        {
             throw ex;
         }
}

public Boolean ExecutQuery(string Query)
{
       try
       {
              CreateCommand(Query);
               return true;
        }
        catch (Exception ex)
        {
              throw ex;
         }
}

HIde & Display Taskbar & Task Manager & Close All Open Window



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace Mesoft
{
    namespace WindowActivites
    {
        public class WindowOperation
        {
            #region "Variable Declaration";
            public static int intLLKey;
            public const int WH_KEYBOARD_LL = 13;
            #endregion

            #region "Stuctures"
            public struct KBDLLHOOKSTRUCT
            {
                public int vkCode;
                public int scanCode;
                public int flags;
                public int time;
                public int dwExtraInfo;
            }
            #endregion

            #region "Methods"
            public void KillTaskManager()
            {
                Microsoft.Win32.RegistryKey regkey;
                string keyValueInt = "1";
                string subKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";

                try
                {
                    regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(subKey);
                    regkey.SetValue("DisableTaskMgr", keyValueInt);
                    regkey.Close();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            [DllImport("user32.dll")]
            private static extern int FindWindow(string className, string windowText);
            [DllImport("user32.dll")]
            private static extern int ShowWindow(int hwnd, int command);

            [DllImport("user32", EntryPoint = "SetWindowsHookExA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
            public static extern int SetWindowsHookEx(int idHook, LowLevelKeyboardProcDelegate lpfn, int hMod, int dwThreadId);
            [DllImport("user32", EntryPoint = "UnhookWindowsHookEx", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
            public static extern int UnhookWindowsHookEx(int hHook);
            public delegate int LowLevelKeyboardProcDelegate(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam);
            [DllImport("user32", EntryPoint = "CallNextHookEx", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
            public static extern int CallNextHookEx(int hHook, int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam);

            public void SetWindowsHookEx()
            {
                try
                {
                    SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, System.Runtime.InteropServices.Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]).ToInt32(), 0);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            public int LowLevelKeyboardProc(int nCode, int wParam, ref KBDLLHOOKSTRUCT lParam)
            {
                try
                {
                    bool blnEat = false;

                    switch (wParam)
                    {
                        case 256:
                        case 257:
                        case 260:
                        case 261:
                            //Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key,
                            blnEat = ((lParam.vkCode == 9) && (lParam.flags == 32)) | ((lParam.vkCode == 27) && (lParam.flags == 32)) | ((lParam.vkCode == 27) && (lParam.flags == 0)) | ((lParam.vkCode == 91) && (lParam.flags == 1)) | ((lParam.vkCode == 92) && (lParam.flags == 1)) | ((lParam.vkCode == 73) && (lParam.flags == 0));
                            break;
                    }

                    if (blnEat == true)
                    {
                        return 1;
                    }
                    else
                    {
                        return CallNextHookEx(0, nCode, wParam, ref lParam);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }


            public void KillStartMenu()
            {
                try
                {
                    int hwnd = FindWindow("Shell_TrayWnd", "");
                    ShowWindow(hwnd, 0);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            public void ShowStartMenu()
            {
                try
                {
                    int hwnd = FindWindow("Shell_TrayWnd", "");
                    ShowWindow(hwnd, 1);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            public void ShowTaskManager()
            {
                try
                {
                    string subKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
                    Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser;
                    Microsoft.Win32.RegistryKey sk1 = rk.OpenSubKey(subKey);
                    if (sk1 != null)
                    {
                        rk.DeleteSubKeyTree(subKey);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            public void CloseAllWindow()
            {
                try
                {
                    foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses(System.Environment.MachineName))
                    {
                        if (p.MainWindowHandle != IntPtr.Zero)
                        {
                            p.Kill();
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            #endregion
        }
    }
}

Validating EMAIL Address



using System.Text.RegularExpressions;

public Boolean IsValidationEmail(string Email)
{
      try
      {
               Regex reg = new Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
               if (Email.Length > 0)
               {
                        MatchText(reg, Email, "Valid E-Mail expected");
                        return true;
                }
                else
                {
                        throw new Exception("Email length is must be more then zero");
                 }
        }
        catch (Exception ex)
        {
                 throw ex;
         }
}


 private Boolean MatchText(Regex reg, string EmailText, string Message)
 {
       try
       {
                    if (!reg.IsMatch(EmailText))
                    {
                        throw new Exception("Please Check, Invalid Email");
                    }
                    else
                    {
                        return true;
                    }
        }
        catch (Exception ex)
        {
                    throw ex;
        }
}

Read Value Form RS232 PORT


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SerialPortExample
{
    public partial class Form1 : Form
    {
      
        public Form1()
        {
            InitializeComponent();
            foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
            {
                listBox1.Items.Add(s);
                serialPort1.Open();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
          
        }

        private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
        {
            try
            {
                textBox1.Text = serialPort1.ReadExisting();
                textBox1.Text = serialPort1.ReadLine().ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

Print Using Graphics



private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            try
            {
                //r is Reader object
                System.Drawing.Font printFont = new Font("Arial", 9, FontStyle.Italic);
                System.Drawing.Font HeadFont = new Font("Arial", 12, FontStyle.Bold);
              
                com.Connection = con;
                com.CommandText = "Select * from DataTab";
                r = com.ExecuteReader();
                int y = 40;

                //////////////Draw Heading///////////////
                e.Graphics.DrawString("Name", HeadFont, Brushes.Black, 10, 10);
                e.Graphics.DrawString("Marks", HeadFont, Brushes.Black, 80, 10);
                //////////////Drawing Line//////////////////
                Pen p=new Pen(Color.Black,2);
                e.Graphics.DrawLine(p, 10, 30, 130, 30);
              

                while (r.Read())
                {
                    e.Graphics.DrawString(r.GetValue(0).ToString(), printFont, Brushes.Black, 10, y);
                    e.Graphics.DrawString(r.GetValue(1).ToString(), printFont, Brushes.Black, 90, y);
                    y += 20;
                }
                e.Graphics.DrawLine(p, 75, 10, 75, y);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                r.Close();
            }
        }

String Format


String Format for Double [C#]
 The following examples show how to format float numbers to string in C#. You can use static method String.Format or instance methods double.ToString and float.ToString. Digits after decimal point This example formats double to string with fixed number of decimal places.

==============================================
 For two decimal places use pattern „0.00“. If a float number has less decimal places, the rest digits on the right will be zeroes. If it has more decimal places, the number will be rounded. [C#]
// just two decimal places

String.Format("{0:0.00}", 123.4567)  // "123.46"
String.Format("{0:0.00}", 123.4);       // "123.40"
String.Format("{0:0.00}", 123.0);       // "123.00"
==============================================

==============================================
 Next example formats double to string with floating number of decimal places.
E.g. for maximal two decimal places use pattern „0.##“. [C#] // max. two decimal places
String.Format("{0:0.##}", 123.4567); // "123.46"
String.Format("{0:0.##}", 123.4);       // "123.4"
String.Format("{0:0.##}", 123.0);     // "123"
==============================================

==============================================
Digits before decimal point If you want a float number to have any minimal number of digits before decimal point use N-times zero before decimal point.
E.g. pattern „00.0“ formats a float number to string with at least two digits before decimal point and one digit after that. [C#]

// at least two digits before decimal point
String.Format("{0:00.0}", 123.4567); // "123.5"
String.Format("{0:00.0}", 23.4567);  // "23.5"
String.Format("{0:00.0}", 3.4567);   // "03.5"
 String.Format("{0:00.0}", -3.4567); // "-03.5"
==============================================

==============================================
 Thousands separator To format double to string with use of thousands separator use zero and comma separator before an usual float formatting pattern,
e.g. pattern „0,0.0“ formats the number to use thousands separators and to have one decimal place. [C#]

String.Format("{0:0,0.0}", 12345.67); // "12,345.7"
String.Format("{0:0,0}", 12345.67);  // "12,346"
==============================================

==============================================
 Zero Float numbers between zero and one can be formatted in two ways, with or without leading zero before decimal point. To format number without a leading zero use # before point. For example „#.0“ formats number to have one decimal place and zero to N digits before decimal point (e.g. „.5“ or „123.5“).

 Following code shows how can be formatted a zero (of double type). [C#]
String.Format("{0:0.0}", 0.0); // "0.0"
String.Format("{0:0.#}", 0.0); // "0"
String.Format("{0:#.0}", 0.0); // ".0"
String.Format("{0:#.#}", 0.0); // ""
==============================================

==============================================
 Align numbers with spaces To align float number to the right use comma „,“ option before the colon. Type comma followed by a number of spaces,
e.g. „0,10:0.0“ (this can be used only in String.Format method, not in double.ToString method). To align numbers to the left use negative number of spaces. [C#]

String.Format("{0,10:0.0}", 123.4567); // " 123.5"
String.Format("{0,-10:0.0}", 123.4567); // "123.5 "
String.Format("{0,10:0.0}", -123.4567); // " -123.5"
String.Format("{0,-10:0.0}", -123.4567); // "-123.5 "
==============================================

==============================================
 Custom formatting for negative numbers and zero If you need to use custom format for negative float numbers or zero, use semicolon separator „;“ to split pattern to three sections. The first section formats positive numbers, the second section formats negative numbers and the third section formats zero. If you omit the last section, zero will be formatted using the first section. [C#]

String.Format("{0:0.00;minus 0.00;zero}", 123.4567); // "123.46"
String.Format("{0:0.00;minus 0.00;zero}", -123.4567); // "minus 123.46"
String.Format("{0:0.00;minus 0.00;zero}", 0.0); // "zero"
==============================================

==============================================
 Some funny examples As you could notice in the previous example, you can put any text into formatting pattern,
 e.g. before an usual pattern „my text 0.0“. You can even put any text between the zeroes, e.g. „0aaa.bbb0“. [C#]

String.Format("{0:my number is 0.0}", 12.3); // "my number is 12.3"
String.Format("{0:0aaa.bbb0}", 12.3); // "12aaa.bbb3"
==============================================

InputBox in C#.net


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Navjivan2008.Transactions
{

    #region InputBox return result

    ///

    /// Class used to store the result of an InputBox.Show message.
    ///

    public class InputBoxResult
    {
        public DialogResult ReturnCode;
        public string Text;
    }

    #endregion

    ///

    /// Summary description for InputBox.
    ///

    public class InputBox
    {

        #region Private Windows Contols and Constructor

        // Create a new instance of the form.
        private static Form frmInputDialog;
        private static Label lblPrompt;
        private static Button btnOK;
        private static Button btnCancel;
        private static TextBox txtInput;

        public InputBox()
        {
        }

        #endregion

        #region Private Variables

        private static string _formCaption = string.Empty;
        private static string _formPrompt = string.Empty;
        private static InputBoxResult _outputResponse = new InputBoxResult();
        private static string _defaultValue = string.Empty;
        private static int _xPos = -1;
        private static int _yPos = -1;

        #endregion

        #region Windows Form code

        private static void InitializeComponent()
        {
            // Create a new instance of the form.
            frmInputDialog = new Form();
            lblPrompt = new Label();
            btnOK = new Button();
            btnCancel = new Button();
            txtInput = new TextBox();
            frmInputDialog.SuspendLayout();
          
          
            //
            // lblPrompt
            //
            lblPrompt.Anchor = ((AnchorStyles)((((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right)));
            lblPrompt.BackColor = Color.Transparent;
            lblPrompt.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((Byte)(0)));
            lblPrompt.Location = new System.Drawing.Point(13, 13);
            lblPrompt.Name = "lblPrompt";
            lblPrompt.AutoSize = true;
            lblPrompt.TabIndex = 3;
            //
            // btnOK
            //
            btnOK.DialogResult = DialogResult.OK;
            btnOK.Location = new System.Drawing.Point(56, 69);
            btnOK.Name = "btnOK";
            btnOK.Size = new Size(75, 23);
            btnOK.TabIndex = 1;
            btnOK.Text = "&OK";
            btnOK.Click += new EventHandler(btnOK_Click);
            btnOK.UseVisualStyleBackColor = true;
            //
            // btnCancel
            //
            btnCancel.DialogResult = DialogResult.Cancel;
            btnCancel.Location = new System.Drawing.Point(137, 69);
            btnCancel.Name = "btnCancel";
            btnCancel.Size = new System.Drawing.Size(75, 23);
            btnCancel.TabIndex = 2;
            btnCancel.Text = "&Cancel";
            btnCancel.Click += new EventHandler(btnCancel_Click);
            btnCancel.UseVisualStyleBackColor = true;
            //
            // txtInput
            //
            txtInput.Location = new System.Drawing.Point(12, 38);
            txtInput.Name = "txtInput";
            txtInput.Size = new System.Drawing.Size(199, 20);
            txtInput.TabIndex = 0;
            txtInput.Text = "";
            //
            // InputBoxDialog
            //
            frmInputDialog.AutoScaleBaseSize = new Size(5, 13);
            frmInputDialog.ClientSize = new System.Drawing.Size(223, 99);
            frmInputDialog.Controls.Add(txtInput);
            frmInputDialog.Controls.Add(btnCancel);
            frmInputDialog.Controls.Add(btnOK);
            frmInputDialog.Controls.Add(lblPrompt);
            frmInputDialog.FormBorderStyle = FormBorderStyle.FixedDialog;
            frmInputDialog.MaximizeBox = false;
            frmInputDialog.MinimizeBox = false;
            frmInputDialog.Name = "InputBoxDialog";
            frmInputDialog.ResumeLayout(false);
            frmInputDialog.BackColor = Color.White;
        }

        #endregion

        #region Private function, InputBox Form move and change size

        static private void LoadForm()
        {
            OutputResponse.ReturnCode = DialogResult.Ignore;
            OutputResponse.Text = string.Empty;

            txtInput.Text = _defaultValue;
            lblPrompt.Text = _formPrompt;
            frmInputDialog.Text = _formCaption;

            // Retrieve the working rectangle from the Screen class
            // using the PrimaryScreen and the WorkingArea properties.
            System.Drawing.Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;

            if ((_xPos >= 0 && _xPos < workingRectangle.Width - 100) && (_yPos >= 0 && _yPos < workingRectangle.Height - 100))
            {
                frmInputDialog.StartPosition = FormStartPosition.Manual;
                frmInputDialog.Location = new System.Drawing.Point(_xPos, _yPos);
            }
            else
                frmInputDialog.StartPosition = FormStartPosition.CenterScreen;


            string PrompText = lblPrompt.Text;

            int n = 0;
            int Index = 0;
            while (PrompText.IndexOf("\n", Index) > -1)
            {
                Index = PrompText.IndexOf("\n", Index) + 1;
                n++;
            }

            if (n == 0)
                n = 1;

            System.Drawing.Point Txt = txtInput.Location;
            Txt.Y = Txt.Y + (n * 4);
            txtInput.Location = Txt;
            System.Drawing.Size form = frmInputDialog.Size;
            form.Height = form.Height + (n * 4);
            frmInputDialog.Size = form;

            txtInput.SelectionStart = 0;
            txtInput.SelectionLength = txtInput.Text.Length;
            txtInput.Focus();
        }

        #endregion

        #region Button control click event

        static private void btnOK_Click(object sender, System.EventArgs e)
        {
            OutputResponse.ReturnCode = DialogResult.OK;
            OutputResponse.Text = txtInput.Text;
            frmInputDialog.Dispose();
        }

        static private void btnCancel_Click(object sender, System.EventArgs e)
        {
            OutputResponse.ReturnCode = DialogResult.Cancel;
            OutputResponse.Text = string.Empty; //Clean output response
            frmInputDialog.Dispose();
        }

        #endregion

        #region Public Static Show functions

        static public InputBoxResult Show(string Prompt)
        {
            InitializeComponent();
            FormPrompt = Prompt;

            // Display the form as a modal dialog box.
            LoadForm();
            frmInputDialog.ShowDialog();
            return OutputResponse;
        }

        static public InputBoxResult Show(string Prompt, string Title)
        {
            InitializeComponent();

            FormCaption = Title;
            FormPrompt = Prompt;

            // Display the form as a modal dialog box.
            LoadForm();
            frmInputDialog.ShowDialog();
            return OutputResponse;
        }

        static public InputBoxResult Show(string Prompt, string Title, string Default)
        {
            InitializeComponent();

            FormCaption = Title;
            FormPrompt = Prompt;
            DefaultValue = Default;

            // Display the form as a modal dialog box.
            LoadForm();
            frmInputDialog.ShowDialog();
            return OutputResponse;
        }

        static public InputBoxResult Show(string Prompt, string Title, string Default, int XPos, int YPos)
        {
            InitializeComponent();
            FormCaption = Title;
            FormPrompt = Prompt;
            DefaultValue = Default;
            XPosition = XPos;
            YPosition = YPos;

            // Display the form as a modal dialog box.
            LoadForm();
            frmInputDialog.ShowDialog();
            return OutputResponse;
        }

        #endregion

        #region Private Properties

        static private string FormCaption
        {
            set
            {
                _formCaption = value;
            }
        } // property FormCaption

        static private string FormPrompt
        {
            set
            {
                _formPrompt = value;
            }
        } // property FormPrompt

        static private InputBoxResult OutputResponse
        {
            get
            {
                return _outputResponse;
            }
            set
            {
                _outputResponse = value;
            }
        } // property InputResponse

        static private string DefaultValue
        {
            set
            {
                _defaultValue = value;
            }
        } // property DefaultValue

        static private int XPosition
        {
            set
            {
                if (value >= 0)
                    _xPos = value;
            }
        } // property XPos

        static private int YPosition
        {
            set
            {
                if (value >= 0)
                    _yPos = value;
            }
        } // property YPos

        #endregion
    }
}