Simple Column Find dialog

from the Artful MySQL Tips List


The look of a dialog is subject to individual and enterprise preferences & requirements. You will likely want to design your own, but here is a simple starter.
  public partial class FindDlg : Form {
    private string strFind = "";
    public FindDlg( string col ) {
      InitializeComponent();
      this.lblPrompt.Text += col + ":";
      tbFind.KeyDown +=new KeyEventHandler(tbFind_KeyDown);
      tbFind.KeyPress +=new KeyPressEventHandler(tbFind_KeyPress);
    }

    public string UserFindSpec {
      get { return strFind; }
    }

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

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

    private bool isSemiColon = false;
    private bool isClose = false;
    private bool isAbandon = false;

    private void tbFind_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e ) {
      if ( e.KeyCode == Keys.OemSemicolon ) isSemiColon = true;
      else if ( e.KeyCode == Keys.Escape ) isAbandon = true;
      else if ( e.KeyCode == Keys.Enter ) isClose = true;
    }

    private void tbFind_KeyPress( object sender, System.Windows.Forms.KeyPressEventArgs e ) {
      if ( isSemiColon ) e.Handled = true;
      else if( isAbandon ) {
        e.Handled = true;
        this.Close();
      }
      else if( isClose ) {
        e.Handled = true;
        strFind = tbFind.Text.ToString();
        this.Close();
      }
    }
  }


Return to the Artful MySQL Tips page