Click here to Skip to main content
15,897,891 members
Articles / Desktop Programming / Windows Forms

ADSI Hunter

Rate me:
Please Sign up or sign in to vote.
4.79/5 (9 votes)
26 Oct 2010CPOL4 min read 54.3K   1.2K   34  
Active Directory lookup utility
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ADSIHunter
{
    /// <summary>
    /// Encapsulate the search parameter entry.
    /// </summary>
    public partial class frmSearch : Form
    {
        #region > Private Data <
        /// <summary>
        /// Error message.
        /// </summary>
        private const string _Error = "Please provide something to search for.";

        /// <summary>
        /// Dialog cancelled flag.
        /// </summary>
        private bool _Cancelled = false;

        /// <summary>
        /// The user entered search string.
        /// </summary>
        private string _UserSrch = string.Empty;
        #endregion

        #region > Constructor <
        /// <summary>
        /// Instantiate object.
        /// </summary>
        public frmSearch(string Title)
        {
            InitializeComponent();
            tbTitle.Text = Title;
        }
        #endregion

        #region > Event Handlers <
        /// <summary>
        /// Search button click event handler.
        /// </summary>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (tbSearchText.Text.Trim().Length < 1)
            {
                errProvider.SetError(tbSearchText, _Error);
                tbError.Text = _Error;
                tbSearchText.Focus();
                return;
            }
            tbError.Text = string.Empty;
            errProvider.Clear();

            _UserSrch = tbSearchText.Text.Trim();
            this.DialogResult = DialogResult.OK;
            this.Hide();
        }

        /// <summary>
        /// Cancel button click event handler.
        /// </summary>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            _UserSrch = string.Empty;
            this.DialogResult = DialogResult.Cancel;
            this.Hide();
        }
        #endregion

        #region > Public Properties <
        /// <summary>
        /// Get the cancelled flag.
        /// </summary>
        public bool Cancelled
        {
            get { return _Cancelled; }
        }

        /// <summary>
        /// Get the user entered search data.
        /// </summary>
        public string UserSearch
        {
            get { return _UserSrch; }
        }
        #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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
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