Sunday, February 14, 2016

EnhancedBoxHelper .NET WinForm component helper

EnhancedBoxHelper is a open source enhanced component helper for .NET WinForm.



It's adds some advanced functions to an existing componente:
  • ComboBox
  • TextBox
  • DateTimePicker
by using the generetor helper.

It requires Microsoft Windows with .NET framework 4.0 or more.

It's basically a static class helper, that attaches events to a component.

One a TextBox you could attach the
  • Deselect on ESC press function: cleans the component if ESC key is pressed
  • Show the Helper form on Right click: show a popup form that lists a bounce of preselected values for the component
  • Show a Tooptip on Mouse Over: show a Tooltip that informs the user about the data selected
The ComboBox also has the
  • Deselect on ESC press function: cleans the component if ESC key is pressed
  • Show the Helper form on Right click: show a popup form that lists a bounce of preselected values for the component
  • Autocomplete on ENTER press function: autocomplete the selected item if ENTER key is pressed
  • Show a Tooptip on Mouse Over: show a Tooltip that informs the user about the data selected
DateTimePicker enhanchments includes :
  • Fast Select Key:
    • Press n or N to set now datetime
    • Press t or T or d or D to set today date
    • Press w or W to set the first, or last day of the week
    • Press m or N to set the first, or last day of the month
    • Press y or Y to set the first, o last day of the year
  • Move to the next datepart on / (slash) press
  • Interval helper on date selector. By setting a interval helper between two DateTimePicker, the user can select range of dates using some helpfull shortcut, or a combobox helper. The combobox attached to the helper can contains values that comply with the %d[d|w|m|y] regex. %d is a number, d stands for days, w for weeks, m for months, y for years. As example, if "+1d" is selected the To picker will be set as From +1 day, if "+2w" is selected the To picker will be set as From +2 weeks, and so on. A maximum interval number can be setted, so that the two pickers can never exceed that interval time. The date To select react to date From by custom fast keys:
    • Press CTRL + d or D on the From component will set the To to the same day of the From
    • Press CTRL + w or W on the From component will set the To to +1 week from the From
    • Press CTRL + m or M on the From component will set the To to +1 month from the From
    • Press CTRL + y or Y on the From component will set the To to +1 year from the From
The popup form uses the AdvancedDataGridView component you could find here.
Two small line are printed on the top right corner of any component attached by the autocomplete helper windows. The color of the two lines can be overriden on the static class.

The most of the time one should attach all the helper provied.
Using the attacher helper method is quite simple, you can find a few example in the sample project and a little sample snippets below.

//Sample attachment function
EnhancedComboBoxHelper.AttachComboBox(
  comboBox1,                                    //target component
  new string[] { "Name", "Address" },           //header for autocomplete Form
  _users.ToList().OrderBy(r => r.name).Select(  //load the list for autocomplete Form
    r => new EnhancedComboBoxHelper.Items()
    {
      _id = r.id,                               //id of selection
      _value = r.name,                          //show value
      _values = new string[]                    //values listed
      {
        r.name,
        r.address
      }
     }).ToArray());

//Sample attachment function
EnhancedComboBoxHelper.AttachComboBox(
  comboBox1,                                    //target component
  new string[] { "Name", "Address" },           //header for autocomplete Form
  _users.ToList().OrderBy(r => r.name).Select(  //load the list for autocomplete Form
    r => new EnhancedComboBoxHelper.Items()
    {
      _id = r.id,                               //id of selection
      _value = r.name,                          //show value
      _values = new string[]                    //values listed
      {
        r.name,
        r.address
      }
   }).ToArray(),
   EnhancedComboBoxHelperList.ViewMode.SelectOnDoubleClick,    //selection mode, how the autcomplete Form selection changes is treated
   () => MessageBox.Show(comboBox2.SelectedValue.ToString())); //selection mode action, get's called after the selection on the autcomplete Form changes 

//Sample attachment function
EnhancedDateTimePickerHelper.AttachDateTimePicker(
  dateTimePicker1,                              //target component
  "yyyy/MM/dd");                                //custom format

//Sample attachment function
new EnhancedDateTimePickerHelper.FilterDateHelper(
  dateTimePicker2,                              //target component from
  dateTimePicker3,                              //target component to
  null,                                         //actions to run after the date is changed
  comboBox3,                                    //fast day combobox selector
  365,                                          //max days between from and to date
  DayOfWeek.Monday,                             //first day of the week
  EnhancedDateTimePickerHelper.FilterDateHelper.FromPickerDefaultValue.FirstDayOfWeek,    //select the default day for from datetimepicker
  EnhancedDateTimePickerHelper.FilterDateHelper.ToPickerDefaultValue.FromPickerSameDay);  //select the default day for to datetimepicker



Code

Notes
  • read risk disclaimer
  • excuse my bad english